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 6 : keys.setValueDescription("vector","the value of the local crystalinity for each of the input atoms"); 58 6 : keys.needsAction("ONES"); keys.needsAction("MATRIX_VECTOR_PRODUCT"); 59 6 : keys.needsAction("COMBINE"); keys.needsAction("CUSTOM"); 60 3 : } 61 : 62 1 : LocalCrystallinity::LocalCrystallinity( const ActionOptions& ao): 63 : Action(ao), 64 1 : ActionShortcut(ao) 65 : { 66 : // This builds an adjacency matrix 67 3 : std::string sp_str, specA, specB; parse("SPECIES",sp_str); parse("SPECIESA",specA); parse("SPECIESB",specB); 68 1 : CoordinationNumbers::expandMatrix( true, getShortcutLabel(), sp_str, specA, specB, this ); 69 : // Input for denominator (coord) 70 1 : ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( getShortcutLabel() + "_mat"); 71 1 : plumed_assert( av && av->getNumberOfComponents()>0 && (av->copyOutput(0))->getRank()==2 ); 72 1 : std::string size; Tools::convert( (av->copyOutput(0))->getShape()[1], size ); 73 2 : readInputLine( getShortcutLabel() + "_ones: ONES SIZE=" + size ); 74 2 : readInputLine( getShortcutLabel() + "_denom: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_mat.w," + getShortcutLabel() + "_ones"); 75 : // Input for numerator 76 1 : std::string finput = ""; 77 1 : for(unsigned i=1;; ++i) { 78 4 : std::vector<std::string> gvec; std::string istr; Tools::convert( i, istr ); 79 8 : if( !parseNumberedVector("GVECTOR",i,gvec) ) { break; } 80 3 : if( gvec.size()!=3 ) error("gvectors should have size 3"); 81 : // This is the dot product between the input gvector and the bond vector 82 9 : readInputLine( getShortcutLabel() + "_dot" + istr + ": COMBINE ARG=" + getShortcutLabel() + "_mat.x," + getShortcutLabel() + "_mat.y," + getShortcutLabel() + "_mat.z " 83 6 : "PERIODIC=NO COEFFICIENTS=" + gvec[0] + "," + gvec[1] + "," + gvec[2] ); 84 : // Now calculate the sine and cosine of the dot product 85 6 : readInputLine( getShortcutLabel() + "_cos" + istr + ": CUSTOM ARG=" + getShortcutLabel() +"_mat.w," + getShortcutLabel() + "_dot" + istr + " FUNC=x*cos(y) PERIODIC=NO"); 86 6 : readInputLine( getShortcutLabel() + "_sin" + istr + ": CUSTOM ARG=" + getShortcutLabel() +"_mat.w," + getShortcutLabel() + "_dot" + istr + " FUNC=x*sin(y) PERIODIC=NO"); 87 : // And sum up the sine and cosine over the coordination spheres 88 6 : readInputLine( getShortcutLabel() + "_cossum" + istr + ": MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_cos" + istr + "," + getShortcutLabel() + "_ones"); 89 6 : readInputLine( getShortcutLabel() + "_sinsum" + istr + ": MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_sin" + istr + "," + getShortcutLabel() + "_ones"); 90 : // And average the sine and cosine over the number of bonds 91 6 : readInputLine( getShortcutLabel() + "_cosmean" + istr + ": CUSTOM FUNC=x/y PERIODIC=NO ARG=" + getShortcutLabel() + "_cossum" + istr + "," + getShortcutLabel() + "_denom"); 92 6 : readInputLine( getShortcutLabel() + "_sinmean" + istr + ": CUSTOM FUNC=x/y PERIODIC=NO ARG=" + getShortcutLabel() + "_sinsum" + istr + "," + getShortcutLabel() + "_denom"); 93 : // And work out the square modulus of this complex number 94 6 : readInputLine( getShortcutLabel() + "_" + istr + ": CUSTOM FUNC=x*x+y*y PERIODIC=NO ARG=" + getShortcutLabel() + "_cosmean" + istr + "," + getShortcutLabel() + "_sinmean" + istr); 95 : // These are all the kvectors that we are adding together in the final combine for the final CV 96 3 : if( i>1 ) finput += ","; 97 6 : finput += getShortcutLabel() + "_" + istr; 98 4 : } 99 : // This computes the final CV 100 2 : readInputLine( getShortcutLabel() + ": COMBINE NORMALIZE PERIODIC=NO ARG=" + finput ); 101 : // Now calculate the total length of the vector 102 2 : multicolvar::MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel(), "", this ); 103 1 : } 104 : 105 : } 106 : } 107 :