Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2012-2017 The plumed team 3 : (see the PEOPLE file at the root of the distribution for a list of names) 4 : 5 : See http://www.plumed.org for more information. 6 : 7 : This file is part of plumed, version 2. 8 : 9 : plumed is free software: you can redistribute it and/or modify 10 : it under the terms of the GNU Lesser General Public License as published by 11 : the Free Software Foundation, either version 3 of the License, or 12 : (at your option) any later version. 13 : 14 : plumed is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU Lesser General Public License for more details. 18 : 19 : You should have received a copy of the GNU Lesser General Public License 20 : along with plumed. If not, see <http://www.gnu.org/licenses/>. 21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 22 : #include "core/ActionShortcut.h" 23 : #include "core/ActionRegister.h" 24 : #include "core/PlumedMain.h" 25 : #include "core/ActionSet.h" 26 : #include "core/ActionWithValue.h" 27 : #include "CoordinationNumbers.h" 28 : #include "multicolvar/MultiColvarShortcuts.h" 29 : 30 : #include <complex> 31 : 32 : namespace PLMD { 33 : namespace symfunc { 34 : 35 : //+PLUMEDOC MCOLVAR LOCAL_CRYSTALINITY 36 : /* 37 : Calculate the local crystalinity symmetry function 38 : 39 : \par Examples 40 : 41 : 42 : */ 43 : //+ENDPLUMEDOC 44 : 45 : 46 : class LocalCrystallinity : public ActionShortcut { 47 : public: 48 : static void registerKeywords( Keywords& keys ); 49 : explicit LocalCrystallinity(const ActionOptions&); 50 : }; 51 : 52 : PLUMED_REGISTER_ACTION(LocalCrystallinity,"LOCAL_CRYSTALINITY") 53 : 54 3 : void LocalCrystallinity::registerKeywords( Keywords& keys ) { 55 3 : CoordinationNumbers::shortcutKeywords( keys ); 56 6 : keys.add("numbered","GVECTOR","the coefficients of the linear combinations to compute for the CV"); 57 3 : keys.needsAction("ONES"); 58 3 : keys.needsAction("MATRIX_VECTOR_PRODUCT"); 59 3 : keys.needsAction("COMBINE"); 60 3 : keys.needsAction("CUSTOM"); 61 3 : } 62 : 63 1 : LocalCrystallinity::LocalCrystallinity( const ActionOptions& ao): 64 : Action(ao), 65 1 : ActionShortcut(ao) { 66 : // This builds an adjacency matrix 67 : std::string sp_str, specA, specB; 68 1 : parse("SPECIES",sp_str); 69 1 : parse("SPECIESA",specA); 70 1 : parse("SPECIESB",specB); 71 1 : CoordinationNumbers::expandMatrix( true, getShortcutLabel(), sp_str, specA, specB, this ); 72 : // Input for denominator (coord) 73 1 : ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( getShortcutLabel() + "_mat"); 74 1 : plumed_assert( av && av->getNumberOfComponents()>0 && (av->copyOutput(0))->getRank()==2 ); 75 : std::string size; 76 1 : Tools::convert( (av->copyOutput(0))->getShape()[1], size ); 77 2 : readInputLine( getShortcutLabel() + "_ones: ONES SIZE=" + size ); 78 2 : readInputLine( getShortcutLabel() + "_denom: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_mat.w," + getShortcutLabel() + "_ones"); 79 : // Input for numerator 80 1 : std::string finput = ""; 81 1 : for(unsigned i=1;; ++i) { 82 : std::vector<std::string> gvec; 83 : std::string istr; 84 4 : Tools::convert( i, istr ); 85 8 : if( !parseNumberedVector("GVECTOR",i,gvec) ) { 86 : break; 87 : } 88 3 : if( gvec.size()!=3 ) { 89 0 : error("gvectors should have size 3"); 90 : } 91 : // This is the dot product between the input gvector and the bond vector 92 9 : readInputLine( getShortcutLabel() + "_dot" + istr + ": COMBINE ARG=" + getShortcutLabel() + "_mat.x," + getShortcutLabel() + "_mat.y," + getShortcutLabel() + "_mat.z " 93 6 : "PERIODIC=NO COEFFICIENTS=" + gvec[0] + "," + gvec[1] + "," + gvec[2] ); 94 : // Now calculate the sine and cosine of the dot product 95 6 : readInputLine( getShortcutLabel() + "_cos" + istr + ": CUSTOM ARG=" + getShortcutLabel() +"_mat.w," + getShortcutLabel() + "_dot" + istr + " FUNC=x*cos(y) PERIODIC=NO"); 96 6 : readInputLine( getShortcutLabel() + "_sin" + istr + ": CUSTOM ARG=" + getShortcutLabel() +"_mat.w," + getShortcutLabel() + "_dot" + istr + " FUNC=x*sin(y) PERIODIC=NO"); 97 : // And sum up the sine and cosine over the coordination spheres 98 6 : readInputLine( getShortcutLabel() + "_cossum" + istr + ": MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_cos" + istr + "," + getShortcutLabel() + "_ones"); 99 6 : readInputLine( getShortcutLabel() + "_sinsum" + istr + ": MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_sin" + istr + "," + getShortcutLabel() + "_ones"); 100 : // And average the sine and cosine over the number of bonds 101 6 : readInputLine( getShortcutLabel() + "_cosmean" + istr + ": CUSTOM FUNC=x/y PERIODIC=NO ARG=" + getShortcutLabel() + "_cossum" + istr + "," + getShortcutLabel() + "_denom"); 102 6 : readInputLine( getShortcutLabel() + "_sinmean" + istr + ": CUSTOM FUNC=x/y PERIODIC=NO ARG=" + getShortcutLabel() + "_sinsum" + istr + "," + getShortcutLabel() + "_denom"); 103 : // And work out the square modulus of this complex number 104 6 : readInputLine( getShortcutLabel() + "_" + istr + ": CUSTOM FUNC=x*x+y*y PERIODIC=NO ARG=" + getShortcutLabel() + "_cosmean" + istr + "," + getShortcutLabel() + "_sinmean" + istr); 105 : // These are all the kvectors that we are adding together in the final combine for the final CV 106 3 : if( i>1 ) { 107 : finput += ","; 108 : } 109 6 : finput += getShortcutLabel() + "_" + istr; 110 4 : } 111 : // This computes the final CV 112 2 : readInputLine( getShortcutLabel() + ": COMBINE NORMALIZE PERIODIC=NO ARG=" + finput ); 113 : // Now calculate the total length of the vector 114 2 : multicolvar::MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel(), "", this ); 115 1 : } 116 : 117 : } 118 : } 119 :