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 "multicolvar/MultiColvarShortcuts.h" 24 : #include "core/PlumedMain.h" 25 : #include "core/ActionSet.h" 26 : #include "core/ActionRegister.h" 27 : #include "core/ActionWithValue.h" 28 : #include "CoordinationNumbers.h" 29 : 30 : #include <complex> 31 : 32 : namespace PLMD { 33 : namespace symfunc { 34 : 35 : //+PLUMEDOC MCOLVAR HEXACTIC_PARAMETER 36 : /* 37 : Calculate the hexatic order parameter 38 : 39 : \bug Virial is not working currently 40 : 41 : \par Examples 42 : 43 : 44 : */ 45 : //+ENDPLUMEDOC 46 : 47 : 48 : class HexacticParameter : public ActionShortcut { 49 : private: 50 : void createVectorNormInput( const std::string& ilab, const std::string& olab, const std::string& vlab ); 51 : public: 52 : static void registerKeywords( Keywords& keys ); 53 : explicit HexacticParameter(const ActionOptions&); 54 : }; 55 : 56 : PLUMED_REGISTER_ACTION(HexacticParameter,"HEXACTIC_PARAMETER") 57 : 58 5 : void HexacticParameter::registerKeywords( Keywords& keys ) { 59 5 : CoordinationNumbers::shortcutKeywords( keys ); 60 10 : keys.add("compulsory","PLANE","the plane to use when calculating the value of the order parameter should be xy, xz or yz"); 61 10 : keys.addFlag("VMEAN",false,"calculate the norm of the mean vector."); 62 10 : keys.addOutputComponent("_vmean","VMEAN","the norm of the mean vector"); 63 10 : keys.addFlag("VSUM",false,"calculate the norm of the sum of all the vectors"); 64 10 : keys.addOutputComponent("_vsum","VSUM","the norm of the mean vector"); 65 5 : keys.needsAction("CYLINDRICAL_HARMONIC_MATRIX"); 66 5 : keys.needsAction("ONES"); 67 5 : keys.needsAction("MATRIX_VECTOR_PRODUCT"); 68 5 : keys.needsAction("CUSTOM"); 69 5 : keys.needsAction("MEAN"); 70 5 : keys.needsAction("SUM"); 71 5 : keys.needsAction("COMBINE"); 72 5 : } 73 : 74 1 : HexacticParameter::HexacticParameter( const ActionOptions& ao): 75 : Action(ao), 76 1 : ActionShortcut(ao) { 77 : std::string sp_str, specA, specB; 78 1 : parse("SPECIES",sp_str); 79 1 : parse("SPECIESA",specA); 80 1 : parse("SPECIESB",specB); 81 1 : CoordinationNumbers::expandMatrix( true, getShortcutLabel(), sp_str, specA, specB, this ); 82 : std::string myplane; 83 2 : parse("PLANE",myplane); 84 1 : if( myplane=="xy" ) { 85 2 : readInputLine( getShortcutLabel() + ": CYLINDRICAL_HARMONIC_MATRIX DEGREE=6 ARG=" + getShortcutLabel() + "_mat.x," + getShortcutLabel() + "_mat.y," + getShortcutLabel() + "_mat.w" ); 86 0 : } else if( myplane=="xz" ) { 87 0 : readInputLine( getShortcutLabel() + ": CYLINDRICAL_HARMONIC_MATRIX DEGREE=6 ARG=" + getShortcutLabel() + "_mat.x," + getShortcutLabel() + "_mat.z," + getShortcutLabel() + "_mat.w" ); 88 0 : } else if( myplane=="yz" ) { 89 0 : readInputLine( getShortcutLabel() + ": CYLINDRICAL_HARMONIC_MATRIX DEGREE=6 ARG=" + getShortcutLabel() + "_mat.y," + getShortcutLabel() + "_mat.z," + getShortcutLabel() + "_mat.w" ); 90 : } else { 91 0 : error("invalid input for plane -- should be xy, xz or yz"); 92 : } 93 : // And coordination number 94 1 : ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( getShortcutLabel() + "_mat"); 95 1 : plumed_assert( av && av->getNumberOfComponents()>0 && (av->copyOutput(0))->getRank()==2 ); 96 : std::string size; 97 1 : Tools::convert( (av->copyOutput(0))->getShape()[1], size ); 98 2 : readInputLine( getShortcutLabel() + "_ones: ONES SIZE=" + size ); 99 2 : readInputLine( getShortcutLabel() + "_rm: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + ".rm," + getShortcutLabel() + "_ones"); 100 2 : readInputLine( getShortcutLabel() + "_im: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + ".im," + getShortcutLabel() + "_ones"); 101 : // Input for denominator (coord) 102 2 : readInputLine( getShortcutLabel() + "_denom: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_mat.w," + getShortcutLabel() + "_ones"); 103 : // Divide real part by coordination numbers 104 2 : readInputLine( getShortcutLabel() + "_rmn: CUSTOM ARG=" + getShortcutLabel() + "_rm," + getShortcutLabel() + "_denom FUNC=x/y PERIODIC=NO"); 105 : // Devide imaginary part by coordination number 106 2 : readInputLine( getShortcutLabel() + "_imn: CUSTOM ARG=" + getShortcutLabel() + "_im," + getShortcutLabel() + "_denom FUNC=x/y PERIODIC=NO"); 107 : 108 : // If we are doing VMEAN determine sum of vector components 109 : bool do_vmean; 110 1 : parseFlag("VMEAN",do_vmean); 111 1 : if( do_vmean ) { 112 : // Real part 113 0 : readInputLine( getShortcutLabel() + "_rms: MEAN ARG=" + getShortcutLabel() + "_rmn PERIODIC=NO"); 114 : // Imaginary part 115 0 : readInputLine( getShortcutLabel() + "_ims: MEAN ARG=" + getShortcutLabel() + "_imn PERIODIC=NO"); 116 : // Now calculate the total length of the vector 117 0 : createVectorNormInput( getShortcutLabel(), getShortcutLabel() + "_vmean", "ms" ); 118 : } 119 : bool do_vsum; 120 1 : parseFlag("VSUM",do_vsum); 121 1 : if( do_vsum ) { 122 : // Real part 123 0 : readInputLine( getShortcutLabel() + "_rmz: SUM ARG=" + getShortcutLabel() + "_rmn PERIODIC=NO"); 124 : // Imaginary part 125 0 : readInputLine( getShortcutLabel() + "_imz: SUM ARG=" + getShortcutLabel() + "_imn PERIODIC=NO"); 126 : // Now calculate the total length of the vector 127 0 : createVectorNormInput( getShortcutLabel(), getShortcutLabel() + "_vsum", "mz" ); 128 : } 129 : 130 : // Now calculate the total length of the vector 131 2 : createVectorNormInput( getShortcutLabel(), getShortcutLabel() + "_norm", "mn" ); 132 2 : multicolvar::MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel() + "_norm", "", this ); 133 1 : } 134 : 135 1 : void HexacticParameter::createVectorNormInput( const std::string& ilab, const std::string& olab, const std::string& vlab ) { 136 2 : readInputLine( olab + "2: COMBINE PERIODIC=NO ARG=" + ilab + "_r" + vlab + "," + ilab + "_i" + vlab + " POWERS=2,2" ); 137 2 : readInputLine( olab + ": CUSTOM ARG=" + olab + "2 FUNC=sqrt(x) PERIODIC=NO"); 138 1 : } 139 : 140 : } 141 : } 142 :