Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2013-2023 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 "SingleDomainRMSD.h" 23 : #include "tools/PDB.h" 24 : #include "DRMSD.h" 25 : 26 : namespace PLMD { 27 : 28 527 : SingleDomainRMSD::SingleDomainRMSD( const ReferenceConfigurationOptions& ro ): 29 : ReferenceConfiguration(ro), 30 527 : ReferenceAtoms(ro) { 31 527 : } 32 : 33 458 : void SingleDomainRMSD::readReference( const PDB& pdb ) { 34 458 : readAtomsFromPDB( pdb ); 35 : double wa=0, wd=0; 36 9071 : for(unsigned i=0; i<pdb.size(); ++i) { 37 8613 : wa+=align[i]; 38 8613 : wd+=displace[i]; 39 : } 40 : 41 458 : if(wa>epsilon) { 42 456 : double w=1.0/wa; 43 9039 : for(unsigned i=0; i<pdb.size(); ++i) { 44 8583 : align[i] *= w; 45 : } 46 : } else { 47 2 : double w=1.0/pdb.size(); 48 32 : for(unsigned i=0; i<pdb.size(); ++i) { 49 30 : align[i] = w; 50 : } 51 : } 52 : 53 458 : if(wd>epsilon) { 54 456 : double w=1.0/wd; 55 9039 : for(unsigned i=0; i<pdb.size(); ++i) { 56 8583 : displace[i] *= w; 57 : } 58 : } else { 59 2 : double w=1.0/pdb.size(); 60 32 : for(unsigned i=0; i<pdb.size(); ++i) { 61 30 : displace[i] = w; 62 : } 63 : } 64 : 65 458 : Vector center; 66 9071 : for(unsigned i=0; i<pdb.size(); ++i) { 67 8613 : center+=reference_atoms[i]*align[i]; 68 : } 69 9071 : for(unsigned i=0; i<pdb.size(); ++i) { 70 8613 : reference_atoms[i]-=center; 71 : } 72 458 : } 73 : 74 72 : void SingleDomainRMSD::setReferenceAtoms( const std::vector<Vector>& conf, const std::vector<double>& align_in, const std::vector<double>& displace_in ) { 75 72 : reference_atoms.resize( conf.size() ); 76 72 : align.resize( conf.size() ); 77 72 : displace.resize( conf.size() ); 78 72 : atom_der_index.resize( conf.size() ); 79 : double wa=0, wd=0; 80 1991 : for(unsigned i=0; i<conf.size(); ++i) { 81 1919 : wa+=align_in[i]; 82 1919 : wd+=displace_in[i]; 83 : } 84 : 85 72 : if(wa>epsilon) { 86 71 : double w=1.0/wa; 87 1982 : for(unsigned i=0; i<conf.size(); ++i) { 88 1911 : align[i] = align_in[i] * w; 89 : } 90 : } else { 91 1 : double w=1.0/conf.size(); 92 9 : for(unsigned i=0; i<conf.size(); ++i) { 93 8 : align[i] = w; 94 : } 95 : } 96 : 97 72 : if(wd>epsilon) { 98 71 : double w=1.0/wd; 99 1983 : for(unsigned i=0; i<conf.size(); ++i) { 100 1912 : displace[i] = displace_in[i] * w; 101 : } 102 : } else { 103 1 : double w=1.0/conf.size(); 104 8 : for(unsigned i=0; i<conf.size(); ++i) { 105 7 : displace[i] = w; 106 : } 107 : } 108 : 109 72 : Vector center; 110 1991 : for(unsigned i=0; i<conf.size(); ++i) { 111 1919 : center+=conf[i]*align[i]; 112 1919 : atom_der_index[i]=i; 113 : } 114 1991 : for(unsigned i=0; i<conf.size(); ++i) { 115 1919 : reference_atoms[i]=conf[i]-center; 116 : } 117 72 : setupRMSDObject(); 118 72 : } 119 : 120 130838 : double SingleDomainRMSD::calculate( const std::vector<Vector>& pos, const Pbc& pbc, ReferenceValuePack& myder, const bool& squared ) const { 121 130838 : return calc( pos, pbc, myder, squared ); 122 : } 123 : 124 140941 : double SingleDomainRMSD::calc( const std::vector<Vector>& pos, const Pbc& pbc, const std::vector<Value*>& vals, const std::vector<double>& arg, 125 : ReferenceValuePack& myder, const bool& squared ) const { 126 : plumed_dbg_assert( vals.size()==0 && pos.size()==getNumberOfAtoms() && arg.size()==0 ); 127 140941 : return calc( pos, pbc, myder, squared ); 128 : } 129 : 130 : }