22 #ifdef __PLUMED_HAS_ALMOST
25 #include "ActionRegister.h"
26 #include "core/PlumedMain.h"
27 #include "core/Atoms.h"
28 #include "tools/Communicator.h"
34 #include <almost/mdb.h>
35 #include <almost/pdb.h>
36 #include <almost/forcefield/const/camshift2.h>
37 #include <almost/io/formostream.h>
40 using namespace Almost;
153 class CS2Backbone :
public Colvar {
154 vector<CamShift2> cam_list;
166 CS2Backbone(
const ActionOptions&);
168 static void registerKeywords( Keywords& keys );
169 virtual void calculate();
172 PLUMED_REGISTER_ACTION(CS2Backbone,
"CS2BACKBONE")
174 void CS2Backbone::registerKeywords( Keywords& keys ){
175 Colvar::registerKeywords( keys );
176 keys.addFlag(
"SERIAL",
false,
"Perform the calculation in serial - for debug purpose.");
177 keys.add(
"atoms",
"ATOMS",
"The atoms to be included in the calculatios, e.g. the whole protein.");
178 keys.add(
"compulsory",
"DATA",
"data/",
"The folder with the experimental chemical shifts.");
179 keys.add(
"compulsory",
"FF",
"a03_gromacs.mdb",
"The ALMOST force-field to map the atoms' names.");
180 keys.add(
"compulsory",
"FLAT",
"1.0",
"Flat region in the scoring function.");
181 keys.add(
"compulsory",
"NEIGH_FREQ",
"10",
"Period in step for neighbour list update.");
182 keys.add(
"compulsory",
"WRITE_CS",
"0",
"Write the back-calculated chemical shifts every # steps.");
183 keys.add(
"compulsory",
"NRES",
"Number of residues, corresponding to the number of chemical shifts.");
184 keys.add(
"optional",
"TERMINI",
"Defines the protonation states of the chain-termini.");
185 keys.addFlag(
"CYS-DISU",
false,
"Set to TRUE if your system has disulphide bridges.");
186 keys.addFlag(
"ENSEMBLE",
false,
"Set to TRUE if you want to average over multiple replicas.");
187 keys.remove(
"NOPBC");
190 CS2Backbone::CS2Backbone(
const ActionOptions&ao):
201 parse(
"DATA",stringa_data);
203 string stringa_forcefield;
204 parse(
"FF",stringa_forcefield);
210 parse(
"FLAT", grains);
213 parse(
"NEIGH_FREQ", neigh_f);
216 parse(
"WRITE_CS", w_period);
219 parse(
"NRES", numResidues);
224 if(
multi_sim_comm.
Get_size()<2) plumed_merror(
"You CANNOT run Replica-Averaged simulations without running multiple replicas!\n");
227 if(ensemble)
comm.
Sum(&ens_dim, 1);
229 stringadb = stringa_data + string(
"/camshift.db");
230 stringamdb = stringa_data + string(
"/") + stringa_forcefield;
231 stringapdb = stringa_data + string(
"/template.pdb");
234 Almost::MDB mdb((
char*)stringamdb.c_str());
236 Almost::PDB pdb((
char*)stringapdb.c_str());
238 vector<string> termini;
240 parse(
"TERMINI",stringa_mol);
241 if(stringa_mol.length()>0) {
242 int num_chains = pdb[0].size();
244 if(data.size()!=2*num_chains) plumed_merror(
"You have to define both the NTerm and the CTerm for each chain of your system!\n");
245 for(
unsigned i=0;i<data.size();i++) termini.push_back(data[i]);
247 int num_chains = pdb[0].size();
248 for(
unsigned i=0;i<(2*num_chains);i++) termini.push_back(
"DEFAULT");
252 for(
unsigned i=0;i<pdb[0].size();i++){
257 p.build_missing(pdb[0][i],mdb,termini[j],termini[j+1]);
258 if(disu) p.auto_disu_bonds(2.9,mdb);
259 molecules.add_protein(p);
263 mol2pdb(molecules,
"converted-template.pdb");
266 CamShift2
a = CamShift2(molecules, stringadb);
269 stringadb = stringa_data + string(
"/CAshifts.dat");
271 a.read_cs(stringadb,
"CA");
272 stringadb = stringa_data + string(
"/CBshifts.dat");
274 a.read_cs(stringadb,
"CB");
275 stringadb = stringa_data + string(
"/Cshifts.dat");
277 a.read_cs(stringadb,
"C");
278 stringadb = stringa_data + string(
"/HAshifts.dat");
280 a.read_cs(stringadb,
"HA");
281 stringadb = stringa_data + string(
"/Hshifts.dat");
283 a.read_cs(stringadb,
"H");
284 stringadb = stringa_data + string(
"/Nshifts.dat");
286 a.read_cs(stringadb,
"N");
288 a.remove_problematic(
"GLN",
"CB");
289 a.remove_problematic(
"ILE",
"CB");
291 a.remove_problematic(
"HIE",
"HA"); a.remove_problematic(
"HIP",
"HA"); a.remove_problematic(
"HSP",
"HA");
292 a.remove_problematic(
"HIE",
"H"); a.remove_problematic(
"HIP",
"H"); a.remove_problematic(
"HSP",
"H");
293 a.remove_problematic(
"HIE",
"N"); a.remove_problematic(
"HIP",
"N"); a.remove_problematic(
"HSP",
"N");
294 a.remove_problematic(
"HIE",
"CA"); a.remove_problematic(
"HIP",
"CA"); a.remove_problematic(
"HSP",
"CA");
295 a.remove_problematic(
"HIE",
"CB"); a.remove_problematic(
"HIP",
"CB"); a.remove_problematic(
"HSP",
"CB");
296 a.remove_problematic(
"HIE",
"C"); a.remove_problematic(
"HIP",
"C"); a.remove_problematic(
"HSP",
"C");
297 a.remove_problematic(
"GLH",
"HA"); a.remove_problematic(
"ASH",
"HA"); a.remove_problematic(
"HSE",
"HA");
298 a.remove_problematic(
"GLH",
"H"); a.remove_problematic(
"ASH",
"H"); a.remove_problematic(
"HSE",
"H");
299 a.remove_problematic(
"GLH",
"N"); a.remove_problematic(
"ASH",
"N"); a.remove_problematic(
"HSE",
"N");
300 a.remove_problematic(
"GLH",
"CA"); a.remove_problematic(
"ASH",
"CA"); a.remove_problematic(
"HSE",
"CA");
301 a.remove_problematic(
"GLH",
"CB"); a.remove_problematic(
"ASH",
"CB"); a.remove_problematic(
"HSE",
"CB");
302 a.remove_problematic(
"GLH",
"C"); a.remove_problematic(
"ASH",
"C"); a.remove_problematic(
"HSE",
"C");
304 a.remove_problematic(
"CYS",
"HA");
305 a.remove_problematic(
"CYS",
"H");
306 a.remove_problematic(
"CYS",
"N");
307 a.remove_problematic(
"CYS",
"CA");
308 a.remove_problematic(
"CYS",
"CB");
309 a.remove_problematic(
"CYS",
"C");
316 if(
serial) {stride=1; rank=0;}
317 if(stride>1)
log.
printf(
" Parallelized over %u processors\n", stride);
318 a.set_mpi(stride, rank);
320 if(ensemble) {
log.
printf(
" ENSEMBLE averaging over %i replicas\n", ens_dim); }
322 a.set_flat_bottom_const(grains);
323 a.set_box_nupdate(neigh_f);
325 cam_list.push_back(a);
327 sh =
new double*[numResidues];
328 sh[0] =
new double[numResidues*6];
329 for (
int i=1; i<numResidues; i++) sh[i]=sh[i-1]+6;
332 ene_pl2alm = 4.186/
plumed.getAtoms().getUnits().getEnergy();
333 len_pl2alm = 10.00*
plumed.getAtoms().getUnits().getLength();
334 for_pl2alm = ene_pl2alm*len_pl2alm;
335 log.
printf(
" Conversion table from plumed to Almost:\n");
339 vector<AtomNumber>
atoms;
343 log<<
" Bibliography "
344 <<
plumed.cite(
"Kohlhoff K, Robustelli P, Cavalli A, Salvatella A, Vendruscolo M, J. Am. Chem. Soc. 131, 13894 (2009)")
345 <<
plumed.cite(
"Camilloni C, Robustelli P, De Simone A, Cavalli A, Vendruscolo M, J. Am. Chem. Soc. 134, 3968 (2012)") <<
"\n";
353 CS2Backbone::~CS2Backbone()
360 void CS2Backbone::calculate()
365 vector<Vector> deriv(getNumberOfAtoms());
366 int N = getNumberOfAtoms();
367 Coor<double> coor(N);
368 Coor<double> forces(N);
371 for(
int i=0; i<numResidues; i++)
for(
unsigned j=0; j<6; j++) sh[i][j]=0.;
373 for (
int i = 0; i < N; i++) {
375 Vector Pos = getPosition(i);
376 coor.coor[ipos] = len_pl2alm*Pos[0];
377 coor.coor[ipos+1] = len_pl2alm*Pos[1];
378 coor.coor[ipos+2] = len_pl2alm*Pos[2];
380 cam_list[0].ens_return_shifts(coor, sh);
381 if(!serial) comm.Sum(&sh[0][0], numResidues*6);
384 if(pperiod>0&&comm.Get_rank()==0) printout = (!(getStep()%pperiod));
387 char tmps1[21], tmps2[21];
390 sprintf(tmps1,
"%li", getStep());
392 sprintf(tmps2,
"%i", multi_sim_comm.Get_rank());
393 csfile = string(
"cs")+tmps2+
"-"+tmps1+string(
".dat");
394 }
else csfile = string(
"cs")+tmps1+string(
".dat");
395 cam_list[0].printout_chemical_shifts(csfile.c_str());
400 fact = 1./((double) ens_dim);
401 if(comm.Get_rank()==0) {
403 multi_sim_comm.Sum(&sh[0][0], numResidues*6);
404 multi_sim_comm.Barrier();
405 for(
unsigned i=0;i<6;i++)
for(
int j=0;j<numResidues;j++) sh[j][i] *= fact;
406 }
else for(
unsigned i=0;i<6;i++)
for(
int j=0;j<numResidues;j++) sh[j][i] = 0.;
408 comm.Sum(&sh[0][0], numResidues*6);
411 energy = cam_list[0].ens_energy_force(coor, forces, sh);
412 if(!serial) comm.Sum(&forces[0][0], N*4);
414 for (
int i = 0; i < N; i++)
418 For[0] = forces.coor[ipos];
419 For[1] = forces.coor[ipos+1];
420 For[2] = forces.coor[ipos+2];
421 deriv[i] = fact*for_pl2alm*For;
422 virial=virial+(-1.*
Tensor(getPosition(i),deriv[i]));
425 for(
unsigned i=0;i<getNumberOfAtoms();++i) setAtomsDerivatives(i,deriv[i]);
426 setValue (ene_pl2alm*energy);
427 setBoxDerivatives (virial);
void zero()
set it to zero
void parseFlag(const std::string &key, bool &t)
Parse one keyword as boolean flag.
void setNotPeriodic()
Set your default value to have no periodicity.
Log & log
Reference to the log stream.
void checkRead()
Check if Action was properly read.
void parseAtomList(const std::string &key, std::vector< AtomNumber > &t)
Parse a list of atoms without a numbered keyword.
void addValueWithDerivatives()
Add a value with the name label that has derivatives.
void requestAtoms(const std::vector< AtomNumber > &a)
#define PLUMED_COLVAR_INIT(ao)
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
Communicator & multi_sim_comm
FileBase & flush()
Flushes the file to disk.
int Get_rank() const
Obtain the rank of the present process.
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
int Get_size() const
Obtain the number of processes.
Vector3d Vector
Alias for three dimensional vectors.
void Sum(T *, int)
Wrapper for MPI_Allreduce with MPI_SUM.