2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
39 #include "gen_vsite.h"
47 #include "gromacs/fileio/pdbio.h"
48 #include "gromacs/gmxpreprocess/add_par.h"
49 #include "gromacs/gmxpreprocess/fflibutil.h"
50 #include "gromacs/gmxpreprocess/gpp_atomtype.h"
51 #include "gromacs/gmxpreprocess/notset.h"
52 #include "gromacs/gmxpreprocess/resall.h"
53 #include "gromacs/gmxpreprocess/toputil.h"
54 #include "gromacs/legacyheaders/names.h"
55 #include "gromacs/legacyheaders/types/ifunc.h"
56 #include "gromacs/math/units.h"
57 #include "gromacs/math/vec.h"
58 #include "gromacs/topology/residuetypes.h"
59 #include "gromacs/topology/symtab.h"
60 #include "gromacs/utility/basedefinitions.h"
61 #include "gromacs/utility/cstringutil.h"
62 #include "gromacs/utility/fatalerror.h"
63 #include "gromacs/utility/futil.h"
64 #include "gromacs/utility/real.h"
65 #include "gromacs/utility/smalloc.h"
68 #define OPENDIR '[' /* starting sign for directive */
69 #define CLOSEDIR ']' /* ending sign for directive */
72 char atomtype
[MAXNAME
]; /* Type for the XH3/XH2 atom */
73 gmx_bool isplanar
; /* If true, the atomtype above and the three connected
74 * ones are in a planar geometry. The two next entries
75 * are undefined in that case
77 int nhydrogens
; /* number of connected hydrogens */
78 char nextheavytype
[MAXNAME
]; /* Type for the heavy atom bonded to XH2/XH3 */
79 char dummymass
[MAXNAME
]; /* The type of MNH* or MCH3* dummy mass to use */
83 /* Structure to represent average bond and angles values in vsite aromatic
84 * residues. Note that these are NOT necessarily the bonds and angles from the
85 * forcefield; many forcefields (like Amber, OPLS) have some inherent strain in
86 * 5-rings (i.e. the sum of angles is !=540, but impropers keep it planar)
89 char resname
[MAXNAME
];
92 struct vsitetop_bond
{
96 } *bond
; /* list of bonds */
97 struct vsitetop_angle
{
102 } *angle
; /* list of angles */
107 DDB_CH3
, DDB_NH3
, DDB_NH2
, DDB_PHE
, DDB_TYR
,
108 DDB_TRP
, DDB_HISA
, DDB_HISB
, DDB_HISH
, DDB_DIR_NR
111 typedef char t_dirname
[STRLEN
];
113 static const t_dirname ddb_dirnames
[DDB_DIR_NR
] = {
125 static int ddb_name2dir(char *name
)
127 /* Translate a directive name to the number of the directive.
128 * HID/HIE/HIP names are translated to the ones we use in Gromacs.
135 for (i
= 0; i
< DDB_DIR_NR
&& index
< 0; i
++)
137 if (!gmx_strcasecmp(name
, ddb_dirnames
[i
]))
147 static void read_vsite_database(const char *ddbname
,
148 t_vsiteconf
**pvsiteconflist
, int *nvsiteconf
,
149 t_vsitetop
**pvsitetoplist
, int *nvsitetop
)
151 /* This routine is a quick hack to fix the problem with hardcoded atomtypes
152 * and aromatic vsite parameters by reading them from a ff???.vsd file.
154 * The file can contain sections [ NH3 ], [ CH3 ], [ NH2 ], and ring residue names.
155 * For the NH3 and CH3 section each line has three fields. The first is the atomtype
156 * (nb: not bonded type) of the N/C atom to be replaced, the second field is
157 * the type of the next heavy atom it is bonded to, and the third field the type
158 * of dummy mass that will be used for this group.
160 * If the NH2 group planar (sp2 N) a different vsite construct is used, so in this
161 * case the second field should just be the word planar.
167 int i
, n
, k
, nvsite
, ntop
, curdir
;
168 t_vsiteconf
*vsiteconflist
;
169 t_vsitetop
*vsitetoplist
;
171 char s1
[MAXNAME
], s2
[MAXNAME
], s3
[MAXNAME
], s4
[MAXNAME
];
173 ddb
= libopen(ddbname
);
175 nvsite
= *nvsiteconf
;
176 vsiteconflist
= *pvsiteconflist
;
178 vsitetoplist
= *pvsitetoplist
;
182 snew(vsiteconflist
, 1);
183 snew(vsitetoplist
, 1);
185 while (fgets2(pline
, STRLEN
-2, ddb
) != NULL
)
187 strip_comment(pline
);
189 if (strlen(pline
) > 0)
191 if (pline
[0] == OPENDIR
)
193 strncpy(dirstr
, pline
+1, STRLEN
-2);
194 if ((ch
= strchr (dirstr
, CLOSEDIR
)) != NULL
)
200 if (!gmx_strcasecmp(dirstr
, "HID") ||
201 !gmx_strcasecmp(dirstr
, "HISD"))
203 sprintf(dirstr
, "HISA");
205 else if (!gmx_strcasecmp(dirstr
, "HIE") ||
206 !gmx_strcasecmp(dirstr
, "HISE"))
208 sprintf(dirstr
, "HISB");
210 else if (!gmx_strcasecmp(dirstr
, "HIP"))
212 sprintf(dirstr
, "HISH");
215 curdir
= ddb_name2dir(dirstr
);
218 gmx_fatal(FARGS
, "Invalid directive %s in vsite database %s",
227 gmx_fatal(FARGS
, "First entry in vsite database must be a directive.\n");
232 n
= sscanf(pline
, "%s%s%s", s1
, s2
, s3
);
233 if (n
< 3 && !gmx_strcasecmp(s2
, "planar"))
235 srenew(vsiteconflist
, nvsite
+1);
236 strncpy(vsiteconflist
[nvsite
].atomtype
, s1
, MAXNAME
-1);
237 vsiteconflist
[nvsite
].isplanar
= TRUE
;
238 vsiteconflist
[nvsite
].nextheavytype
[0] = 0;
239 vsiteconflist
[nvsite
].dummymass
[0] = 0;
240 vsiteconflist
[nvsite
].nhydrogens
= 2;
245 srenew(vsiteconflist
, (nvsite
+1));
246 strncpy(vsiteconflist
[nvsite
].atomtype
, s1
, MAXNAME
-1);
247 vsiteconflist
[nvsite
].isplanar
= FALSE
;
248 strncpy(vsiteconflist
[nvsite
].nextheavytype
, s2
, MAXNAME
-1);
249 strncpy(vsiteconflist
[nvsite
].dummymass
, s3
, MAXNAME
-1);
250 if (curdir
== DDB_NH2
)
252 vsiteconflist
[nvsite
].nhydrogens
= 2;
256 vsiteconflist
[nvsite
].nhydrogens
= 3;
262 gmx_fatal(FARGS
, "Not enough directives in vsite database line: %s\n", pline
);
272 while ((i
< ntop
) && gmx_strcasecmp(dirstr
, vsitetoplist
[i
].resname
))
276 /* Allocate a new topology entry if this is a new residue */
279 srenew(vsitetoplist
, ntop
+1);
280 ntop
++; /* i still points to current vsite topology entry */
281 strncpy(vsitetoplist
[i
].resname
, dirstr
, MAXNAME
-1);
282 vsitetoplist
[i
].nbonds
= vsitetoplist
[i
].nangles
= 0;
283 snew(vsitetoplist
[i
].bond
, 1);
284 snew(vsitetoplist
[i
].angle
, 1);
286 n
= sscanf(pline
, "%s%s%s%s", s1
, s2
, s3
, s4
);
290 k
= vsitetoplist
[i
].nbonds
++;
291 srenew(vsitetoplist
[i
].bond
, k
+1);
292 strncpy(vsitetoplist
[i
].bond
[k
].atom1
, s1
, MAXNAME
-1);
293 strncpy(vsitetoplist
[i
].bond
[k
].atom2
, s2
, MAXNAME
-1);
294 vsitetoplist
[i
].bond
[k
].value
= strtod(s3
, NULL
);
299 k
= vsitetoplist
[i
].nangles
++;
300 srenew(vsitetoplist
[i
].angle
, k
+1);
301 strncpy(vsitetoplist
[i
].angle
[k
].atom1
, s1
, MAXNAME
-1);
302 strncpy(vsitetoplist
[i
].angle
[k
].atom2
, s2
, MAXNAME
-1);
303 strncpy(vsitetoplist
[i
].angle
[k
].atom3
, s3
, MAXNAME
-1);
304 vsitetoplist
[i
].angle
[k
].value
= strtod(s4
, NULL
);
308 gmx_fatal(FARGS
, "Need 3 or 4 values to specify bond/angle values in %s: %s\n", ddbname
, pline
);
312 gmx_fatal(FARGS
, "Didnt find a case for directive %s in read_vsite_database\n", dirstr
);
318 *pvsiteconflist
= vsiteconflist
;
319 *pvsitetoplist
= vsitetoplist
;
320 *nvsiteconf
= nvsite
;
326 static int nitrogen_is_planar(t_vsiteconf vsiteconflist
[], int nvsiteconf
, char atomtype
[])
328 /* Return 1 if atomtype exists in database list and is planar, 0 if not,
329 * and -1 if not found.
332 gmx_bool found
= FALSE
;
333 for (i
= 0; i
< nvsiteconf
&& !found
; i
++)
335 found
= (!gmx_strcasecmp(vsiteconflist
[i
].atomtype
, atomtype
) && (vsiteconflist
[i
].nhydrogens
== 2));
339 res
= (vsiteconflist
[i
-1].isplanar
== TRUE
);
349 static char *get_dummymass_name(t_vsiteconf vsiteconflist
[], int nvsiteconf
, char atom
[], char nextheavy
[])
351 /* Return the dummy mass name if found, or NULL if not set in ddb database */
353 gmx_bool found
= FALSE
;
354 for (i
= 0; i
< nvsiteconf
&& !found
; i
++)
356 found
= (!gmx_strcasecmp(vsiteconflist
[i
].atomtype
, atom
) &&
357 !gmx_strcasecmp(vsiteconflist
[i
].nextheavytype
, nextheavy
));
361 return vsiteconflist
[i
-1].dummymass
;
371 static real
get_ddb_bond(t_vsitetop
*vsitetop
, int nvsitetop
,
373 const char atom1
[], const char atom2
[])
378 while (i
< nvsitetop
&& gmx_strcasecmp(res
, vsitetop
[i
].resname
))
384 gmx_fatal(FARGS
, "No vsite information for residue %s found in vsite database.\n", res
);
387 while (j
< vsitetop
[i
].nbonds
&&
388 ( strcmp(atom1
, vsitetop
[i
].bond
[j
].atom1
) || strcmp(atom2
, vsitetop
[i
].bond
[j
].atom2
)) &&
389 ( strcmp(atom2
, vsitetop
[i
].bond
[j
].atom1
) || strcmp(atom1
, vsitetop
[i
].bond
[j
].atom2
)))
393 if (j
== vsitetop
[i
].nbonds
)
395 gmx_fatal(FARGS
, "Couldnt find bond %s-%s for residue %s in vsite database.\n", atom1
, atom2
, res
);
398 return vsitetop
[i
].bond
[j
].value
;
402 static real
get_ddb_angle(t_vsitetop
*vsitetop
, int nvsitetop
,
403 const char res
[], const char atom1
[],
404 const char atom2
[], const char atom3
[])
409 while (i
< nvsitetop
&& gmx_strcasecmp(res
, vsitetop
[i
].resname
))
415 gmx_fatal(FARGS
, "No vsite information for residue %s found in vsite database.\n", res
);
418 while (j
< vsitetop
[i
].nangles
&&
419 ( strcmp(atom1
, vsitetop
[i
].angle
[j
].atom1
) ||
420 strcmp(atom2
, vsitetop
[i
].angle
[j
].atom2
) ||
421 strcmp(atom3
, vsitetop
[i
].angle
[j
].atom3
)) &&
422 ( strcmp(atom3
, vsitetop
[i
].angle
[j
].atom1
) ||
423 strcmp(atom2
, vsitetop
[i
].angle
[j
].atom2
) ||
424 strcmp(atom1
, vsitetop
[i
].angle
[j
].atom3
)))
428 if (j
== vsitetop
[i
].nangles
)
430 gmx_fatal(FARGS
, "Couldnt find angle %s-%s-%s for residue %s in vsite database.\n", atom1
, atom2
, atom3
, res
);
433 return vsitetop
[i
].angle
[j
].value
;
437 static void count_bonds(int atom
, t_params
*psb
, char ***atomname
,
438 int *nrbonds
, int *nrHatoms
, int Hatoms
[], int *Heavy
,
439 int *nrheavies
, int heavies
[])
441 int i
, heavy
, other
, nrb
, nrH
, nrhv
;
443 /* find heavy atom bound to this hydrogen */
445 for (i
= 0; (i
< psb
->nr
) && (heavy
== NOTSET
); i
++)
447 if (psb
->param
[i
].ai() == atom
)
449 heavy
= psb
->param
[i
].aj();
451 else if (psb
->param
[i
].aj() == atom
)
453 heavy
= psb
->param
[i
].ai();
458 gmx_fatal(FARGS
, "unbound hydrogen atom %d", atom
+1);
460 /* find all atoms bound to heavy atom */
465 for (i
= 0; i
< psb
->nr
; i
++)
467 if (psb
->param
[i
].ai() == heavy
)
469 other
= psb
->param
[i
].aj();
471 else if (psb
->param
[i
].aj() == heavy
)
473 other
= psb
->param
[i
].ai();
478 if (is_hydrogen(*(atomname
[other
])))
485 heavies
[nrhv
] = other
;
497 static void print_bonds(FILE *fp
, int o2n
[],
498 int nrHatoms
, int Hatoms
[], int Heavy
,
499 int nrheavies
, int heavies
[])
503 fprintf(fp
, "Found: %d Hatoms: ", nrHatoms
);
504 for (i
= 0; i
< nrHatoms
; i
++)
506 fprintf(fp
, " %d", o2n
[Hatoms
[i
]]+1);
508 fprintf(fp
, "; %d Heavy atoms: %d", nrheavies
+1, o2n
[Heavy
]+1);
509 for (i
= 0; i
< nrheavies
; i
++)
511 fprintf(fp
, " %d", o2n
[heavies
[i
]]+1);
516 static int get_atype(int atom
, t_atoms
*at
, int nrtp
, t_restp rtp
[],
517 gmx_residuetype_t
*rt
)
524 if (at
->atom
[atom
].m
)
526 type
= at
->atom
[atom
].type
;
530 /* get type from rtp */
531 rtpp
= get_restp(*(at
->resinfo
[at
->atom
[atom
].resind
].name
), nrtp
, rtp
);
532 bNterm
= gmx_residuetype_is_protein(rt
, *(at
->resinfo
[at
->atom
[atom
].resind
].name
)) &&
533 (at
->atom
[atom
].resind
== 0);
534 j
= search_jtype(rtpp
, *(at
->atomname
[atom
]), bNterm
);
535 type
= rtpp
->atom
[j
].type
;
540 static int vsite_nm2type(const char *name
, gpp_atomtype_t atype
)
544 tp
= get_atomtype_type(name
, atype
);
547 gmx_fatal(FARGS
, "Dummy mass type (%s) not found in atom type database",
554 static real
get_amass(int atom
, t_atoms
*at
, int nrtp
, t_restp rtp
[],
555 gmx_residuetype_t
*rt
)
562 if (at
->atom
[atom
].m
)
564 mass
= at
->atom
[atom
].m
;
568 /* get mass from rtp */
569 rtpp
= get_restp(*(at
->resinfo
[at
->atom
[atom
].resind
].name
), nrtp
, rtp
);
570 bNterm
= gmx_residuetype_is_protein(rt
, *(at
->resinfo
[at
->atom
[atom
].resind
].name
)) &&
571 (at
->atom
[atom
].resind
== 0);
572 j
= search_jtype(rtpp
, *(at
->atomname
[atom
]), bNterm
);
573 mass
= rtpp
->atom
[j
].m
;
578 static void my_add_param(t_params
*plist
, int ai
, int aj
, real b
)
580 static real c
[MAXFORCEPARAM
] =
581 { NOTSET
, NOTSET
, NOTSET
, NOTSET
, NOTSET
, NOTSET
};
584 add_param(plist
, ai
, aj
, c
, NULL
);
587 static void add_vsites(t_params plist
[], int vsite_type
[],
588 int Heavy
, int nrHatoms
, int Hatoms
[],
589 int nrheavies
, int heavies
[])
591 int i
, j
, ftype
, other
, moreheavy
;
592 gmx_bool bSwapParity
;
594 for (i
= 0; i
< nrHatoms
; i
++)
596 ftype
= vsite_type
[Hatoms
[i
]];
597 /* Errors in setting the vsite_type should really be caugth earlier,
598 * because here it's not possible to print any useful error message.
599 * But it's still better to print a message than to segfault.
603 gmx_incons("Undetected error in setting up virtual sites");
605 bSwapParity
= (ftype
< 0);
606 vsite_type
[Hatoms
[i
]] = ftype
= abs(ftype
);
607 if (ftype
== F_BONDS
)
609 if ( (nrheavies
!= 1) && (nrHatoms
!= 1) )
611 gmx_fatal(FARGS
, "cannot make constraint in add_vsites for %d heavy "
612 "atoms and %d hydrogen atoms", nrheavies
, nrHatoms
);
614 my_add_param(&(plist
[F_CONSTRNC
]), Hatoms
[i
], heavies
[0], NOTSET
);
625 gmx_fatal(FARGS
, "Not enough heavy atoms (%d) for %s (min 3)",
627 interaction_function
[vsite_type
[Hatoms
[i
]]].name
);
629 add_vsite3_atoms(&plist
[ftype
], Hatoms
[i
], Heavy
, heavies
[0], heavies
[1],
636 moreheavy
= heavies
[1];
640 /* find more heavy atoms */
641 other
= moreheavy
= NOTSET
;
642 for (j
= 0; (j
< plist
[F_BONDS
].nr
) && (moreheavy
== NOTSET
); j
++)
644 if (plist
[F_BONDS
].param
[j
].ai() == heavies
[0])
646 other
= plist
[F_BONDS
].param
[j
].aj();
648 else if (plist
[F_BONDS
].param
[j
].aj() == heavies
[0])
650 other
= plist
[F_BONDS
].param
[j
].ai();
652 if ( (other
!= NOTSET
) && (other
!= Heavy
) )
657 if (moreheavy
== NOTSET
)
659 gmx_fatal(FARGS
, "Unbound molecule part %d-%d", Heavy
+1, Hatoms
[0]+1);
662 add_vsite3_atoms(&plist
[ftype
], Hatoms
[i
], Heavy
, heavies
[0], moreheavy
,
670 gmx_fatal(FARGS
, "Not enough heavy atoms (%d) for %s (min 4)",
672 interaction_function
[vsite_type
[Hatoms
[i
]]].name
);
674 add_vsite4_atoms(&plist
[ftype
],
675 Hatoms
[0], Heavy
, heavies
[0], heavies
[1], heavies
[2]);
679 gmx_fatal(FARGS
, "can't use add_vsites for interaction function %s",
680 interaction_function
[vsite_type
[Hatoms
[i
]]].name
);
686 #define ANGLE_6RING (DEG2RAD*120)
688 /* cosine rule: a^2 = b^2 + c^2 - 2 b c cos(alpha) */
689 /* get a^2 when a, b and alpha are given: */
690 #define cosrule(b, c, alpha) ( sqr(b) + sqr(c) - 2*b*c*cos(alpha) )
691 /* get cos(alpha) when a, b and c are given: */
692 #define acosrule(a, b, c) ( (sqr(b)+sqr(c)-sqr(a))/(2*b*c) )
694 static int gen_vsites_6ring(t_atoms
*at
, int *vsite_type
[], t_params plist
[],
695 int nrfound
, int *ats
, real bond_cc
, real bond_ch
,
696 real xcom
, gmx_bool bDoZ
)
698 /* these MUST correspond to the atnms array in do_vsite_aromatics! */
700 atCG
, atCD1
, atHD1
, atCD2
, atHD2
, atCE1
, atHE1
, atCE2
, atHE2
,
705 real a
, b
, dCGCE
, tmp1
, tmp2
, mtot
, mG
, mrest
;
707 /* CG, CE1 and CE2 stay and each get a part of the total mass,
708 * so the c-o-m stays the same.
715 gmx_incons("Generating vsites on 6-rings");
719 /* constraints between CG, CE1 and CE2: */
720 dCGCE
= std::sqrt( cosrule(bond_cc
, bond_cc
, ANGLE_6RING
) );
721 my_add_param(&(plist
[F_CONSTRNC
]), ats
[atCG
], ats
[atCE1
], dCGCE
);
722 my_add_param(&(plist
[F_CONSTRNC
]), ats
[atCG
], ats
[atCE2
], dCGCE
);
723 my_add_param(&(plist
[F_CONSTRNC
]), ats
[atCE1
], ats
[atCE2
], dCGCE
);
725 /* rest will be vsite3 */
728 for (i
= 0; i
< (bDoZ
? atNR
: atHZ
); i
++)
730 mtot
+= at
->atom
[ats
[i
]].m
;
731 if (i
!= atCG
&& i
!= atCE1
&& i
!= atCE2
&& (bDoZ
|| (i
!= atHZ
&& i
!= atCZ
) ) )
733 at
->atom
[ats
[i
]].m
= at
->atom
[ats
[i
]].mB
= 0;
734 (*vsite_type
)[ats
[i
]] = F_VSITE3
;
738 /* Distribute mass so center-of-mass stays the same.
739 * The center-of-mass in the call is defined with x=0 at
740 * the CE1-CE2 bond and y=0 at the line from CG to the middle of CE1-CE2 bond.
742 xCG
= -bond_cc
+bond_cc
*cos(ANGLE_6RING
);
744 mG
= at
->atom
[ats
[atCG
]].m
= at
->atom
[ats
[atCG
]].mB
= xcom
*mtot
/xCG
;
746 at
->atom
[ats
[atCE1
]].m
= at
->atom
[ats
[atCE1
]].mB
=
747 at
->atom
[ats
[atCE2
]].m
= at
->atom
[ats
[atCE2
]].mB
= mrest
/ 2;
749 /* vsite3 construction: r_d = r_i + a r_ij + b r_ik */
750 tmp1
= dCGCE
*sin(ANGLE_6RING
*0.5);
751 tmp2
= bond_cc
*cos(0.5*ANGLE_6RING
) + tmp1
;
753 a
= b
= -bond_ch
/ tmp1
;
755 add_vsite3_param(&plist
[F_VSITE3
],
756 ats
[atHE1
], ats
[atCE1
], ats
[atCE2
], ats
[atCG
], a
, b
);
757 add_vsite3_param(&plist
[F_VSITE3
],
758 ats
[atHE2
], ats
[atCE2
], ats
[atCE1
], ats
[atCG
], a
, b
);
759 /* CD1, CD2 and CZ: */
761 add_vsite3_param(&plist
[F_VSITE3
],
762 ats
[atCD1
], ats
[atCE2
], ats
[atCE1
], ats
[atCG
], a
, b
);
763 add_vsite3_param(&plist
[F_VSITE3
],
764 ats
[atCD2
], ats
[atCE1
], ats
[atCE2
], ats
[atCG
], a
, b
);
767 add_vsite3_param(&plist
[F_VSITE3
],
768 ats
[atCZ
], ats
[atCG
], ats
[atCE1
], ats
[atCE2
], a
, b
);
770 /* HD1, HD2 and HZ: */
771 a
= b
= ( bond_ch
+ tmp2
) / tmp1
;
772 add_vsite3_param(&plist
[F_VSITE3
],
773 ats
[atHD1
], ats
[atCE2
], ats
[atCE1
], ats
[atCG
], a
, b
);
774 add_vsite3_param(&plist
[F_VSITE3
],
775 ats
[atHD2
], ats
[atCE1
], ats
[atCE2
], ats
[atCG
], a
, b
);
778 add_vsite3_param(&plist
[F_VSITE3
],
779 ats
[atHZ
], ats
[atCG
], ats
[atCE1
], ats
[atCE2
], a
, b
);
785 static int gen_vsites_phe(t_atoms
*at
, int *vsite_type
[], t_params plist
[],
786 int nrfound
, int *ats
, t_vsitetop
*vsitetop
, int nvsitetop
)
788 real bond_cc
, bond_ch
;
791 /* these MUST correspond to the atnms array in do_vsite_aromatics! */
793 atCG
, atCD1
, atHD1
, atCD2
, atHD2
, atCE1
, atHE1
, atCE2
, atHE2
,
797 /* Aromatic rings have 6-fold symmetry, so we only need one bond length.
798 * (angle is always 120 degrees).
800 bond_cc
= get_ddb_bond(vsitetop
, nvsitetop
, "PHE", "CD1", "CE1");
801 bond_ch
= get_ddb_bond(vsitetop
, nvsitetop
, "PHE", "CD1", "HD1");
803 x
[atCG
] = -bond_cc
+bond_cc
*cos(ANGLE_6RING
);
805 x
[atHD1
] = x
[atCD1
]+bond_ch
*cos(ANGLE_6RING
);
807 x
[atHE1
] = x
[atCE1
]-bond_ch
*cos(ANGLE_6RING
);
812 x
[atCZ
] = bond_cc
*cos(0.5*ANGLE_6RING
);
813 x
[atHZ
] = x
[atCZ
]+bond_ch
;
816 for (i
= 0; i
< atNR
; i
++)
818 xcom
+= x
[i
]*at
->atom
[ats
[i
]].m
;
819 mtot
+= at
->atom
[ats
[i
]].m
;
823 return gen_vsites_6ring(at
, vsite_type
, plist
, nrfound
, ats
, bond_cc
, bond_ch
, xcom
, TRUE
);
826 static void calc_vsite3_param(real xd
, real yd
, real xi
, real yi
, real xj
, real yj
,
827 real xk
, real yk
, real
*a
, real
*b
)
829 /* determine parameters by solving the equation system, since we know the
830 * virtual site coordinates here.
832 real dx_ij
, dx_ik
, dy_ij
, dy_ik
;
839 *a
= ( (xd
-xi
)*dy_ik
- dx_ik
*(yd
-yi
) ) / (dx_ij
*dy_ik
- dx_ik
*dy_ij
);
840 *b
= ( yd
- yi
- (*a
)*dy_ij
) / dy_ik
;
844 static int gen_vsites_trp(gpp_atomtype_t atype
, rvec
*newx
[],
845 t_atom
*newatom
[], char ***newatomname
[],
846 int *o2n
[], int *newvsite_type
[], int *newcgnr
[],
847 t_symtab
*symtab
, int *nadd
, rvec x
[], int *cgnr
[],
848 t_atoms
*at
, int *vsite_type
[], t_params plist
[],
849 int nrfound
, int *ats
, int add_shift
,
850 t_vsitetop
*vsitetop
, int nvsitetop
)
853 /* these MUST correspond to the atnms array in do_vsite_aromatics! */
855 atCB
, atCG
, atCD1
, atHD1
, atCD2
, atNE1
, atHE1
, atCE2
, atCE3
, atHE3
,
856 atCZ2
, atHZ2
, atCZ3
, atHZ3
, atCH2
, atHH2
, atNR
858 /* weights for determining the COM's of both rings (M1 and M2): */
859 real mw
[NMASS
][atNR
] = {
860 { 0, 1, 1, 1, 0.5, 1, 1, 0.5, 0, 0,
862 { 0, 0, 0, 0, 0.5, 0, 0, 0.5, 1, 1,
866 real xi
[atNR
], yi
[atNR
];
867 real xcom
[NMASS
], ycom
[NMASS
], alpha
;
868 real b_CD2_CE2
, b_NE1_CE2
, b_CG_CD2
, b_CH2_HH2
, b_CE2_CZ2
;
869 real b_NE1_HE1
, b_CD2_CE3
, b_CE3_CZ3
, b_CB_CG
;
870 real b_CZ2_CH2
, b_CZ2_HZ2
, b_CD1_HD1
, b_CE3_HE3
;
871 real b_CG_CD1
, b_CZ3_HZ3
;
872 real a_NE1_CE2_CD2
, a_CE2_CD2_CG
, a_CB_CG_CD2
, a_CE2_CD2_CE3
;
873 real a_CD2_CG_CD1
, a_CE2_CZ2_HZ2
, a_CZ2_CH2_HH2
;
874 real a_CD2_CE2_CZ2
, a_CD2_CE3_CZ3
, a_CE3_CZ3_HZ3
, a_CG_CD1_HD1
;
875 real a_CE2_CZ2_CH2
, a_HE1_NE1_CE2
, a_CD2_CE3_HE3
;
876 int atM
[NMASS
], tpM
, i
, i0
, j
, nvsite
;
877 real mM
[NMASS
], dCBM1
, dCBM2
, dM1M2
;
879 rvec r_ij
, r_ik
, t1
, t2
;
884 gmx_incons("atom types in gen_vsites_trp");
886 /* Get geometry from database */
887 b_CD2_CE2
= get_ddb_bond(vsitetop
, nvsitetop
, "TRP", "CD2", "CE2");
888 b_NE1_CE2
= get_ddb_bond(vsitetop
, nvsitetop
, "TRP", "NE1", "CE2");
889 b_CG_CD1
= get_ddb_bond(vsitetop
, nvsitetop
, "TRP", "CG", "CD1");
890 b_CG_CD2
= get_ddb_bond(vsitetop
, nvsitetop
, "TRP", "CG", "CD2");
891 b_CB_CG
= get_ddb_bond(vsitetop
, nvsitetop
, "TRP", "CB", "CG");
892 b_CE2_CZ2
= get_ddb_bond(vsitetop
, nvsitetop
, "TRP", "CE2", "CZ2");
893 b_CD2_CE3
= get_ddb_bond(vsitetop
, nvsitetop
, "TRP", "CD2", "CE3");
894 b_CE3_CZ3
= get_ddb_bond(vsitetop
, nvsitetop
, "TRP", "CE3", "CZ3");
895 b_CZ2_CH2
= get_ddb_bond(vsitetop
, nvsitetop
, "TRP", "CZ2", "CH2");
897 b_CD1_HD1
= get_ddb_bond(vsitetop
, nvsitetop
, "TRP", "CD1", "HD1");
898 b_CZ2_HZ2
= get_ddb_bond(vsitetop
, nvsitetop
, "TRP", "CZ2", "HZ2");
899 b_NE1_HE1
= get_ddb_bond(vsitetop
, nvsitetop
, "TRP", "NE1", "HE1");
900 b_CH2_HH2
= get_ddb_bond(vsitetop
, nvsitetop
, "TRP", "CH2", "HH2");
901 b_CE3_HE3
= get_ddb_bond(vsitetop
, nvsitetop
, "TRP", "CE3", "HE3");
902 b_CZ3_HZ3
= get_ddb_bond(vsitetop
, nvsitetop
, "TRP", "CZ3", "HZ3");
904 a_NE1_CE2_CD2
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, "TRP", "NE1", "CE2", "CD2");
905 a_CE2_CD2_CG
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, "TRP", "CE2", "CD2", "CG");
906 a_CB_CG_CD2
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, "TRP", "CB", "CG", "CD2");
907 a_CD2_CG_CD1
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, "TRP", "CD2", "CG", "CD1");
908 /*a_CB_CG_CD1 = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TRP", "CB", "CG", "CD1"); unused */
910 a_CE2_CD2_CE3
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, "TRP", "CE2", "CD2", "CE3");
911 a_CD2_CE2_CZ2
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, "TRP", "CD2", "CE2", "CZ2");
912 a_CD2_CE3_CZ3
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, "TRP", "CD2", "CE3", "CZ3");
913 a_CE3_CZ3_HZ3
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, "TRP", "CE3", "CZ3", "HZ3");
914 a_CZ2_CH2_HH2
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, "TRP", "CZ2", "CH2", "HH2");
915 a_CE2_CZ2_HZ2
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, "TRP", "CE2", "CZ2", "HZ2");
916 a_CE2_CZ2_CH2
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, "TRP", "CE2", "CZ2", "CH2");
917 a_CG_CD1_HD1
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, "TRP", "CG", "CD1", "HD1");
918 a_HE1_NE1_CE2
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, "TRP", "HE1", "NE1", "CE2");
919 a_CD2_CE3_HE3
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, "TRP", "CD2", "CE3", "HE3");
921 /* Calculate local coordinates.
922 * y-axis (x=0) is the bond CD2-CE2.
923 * x-axis (y=0) is perpendicular to the bond CD2-CE2 and
924 * intersects the middle of the bond.
927 yi
[atCD2
] = -0.5*b_CD2_CE2
;
930 yi
[atCE2
] = 0.5*b_CD2_CE2
;
932 xi
[atNE1
] = -b_NE1_CE2
*sin(a_NE1_CE2_CD2
);
933 yi
[atNE1
] = yi
[atCE2
]-b_NE1_CE2
*cos(a_NE1_CE2_CD2
);
935 xi
[atCG
] = -b_CG_CD2
*sin(a_CE2_CD2_CG
);
936 yi
[atCG
] = yi
[atCD2
]+b_CG_CD2
*cos(a_CE2_CD2_CG
);
938 alpha
= a_CE2_CD2_CG
+ M_PI
- a_CB_CG_CD2
;
939 xi
[atCB
] = xi
[atCG
]-b_CB_CG
*sin(alpha
);
940 yi
[atCB
] = yi
[atCG
]+b_CB_CG
*cos(alpha
);
942 alpha
= a_CE2_CD2_CG
+ a_CD2_CG_CD1
- M_PI
;
943 xi
[atCD1
] = xi
[atCG
]-b_CG_CD1
*sin(alpha
);
944 yi
[atCD1
] = yi
[atCG
]+b_CG_CD1
*cos(alpha
);
946 xi
[atCE3
] = b_CD2_CE3
*sin(a_CE2_CD2_CE3
);
947 yi
[atCE3
] = yi
[atCD2
]+b_CD2_CE3
*cos(a_CE2_CD2_CE3
);
949 xi
[atCZ2
] = b_CE2_CZ2
*sin(a_CD2_CE2_CZ2
);
950 yi
[atCZ2
] = yi
[atCE2
]-b_CE2_CZ2
*cos(a_CD2_CE2_CZ2
);
952 alpha
= a_CE2_CD2_CE3
+ a_CD2_CE3_CZ3
- M_PI
;
953 xi
[atCZ3
] = xi
[atCE3
]+b_CE3_CZ3
*sin(alpha
);
954 yi
[atCZ3
] = yi
[atCE3
]+b_CE3_CZ3
*cos(alpha
);
956 alpha
= a_CD2_CE2_CZ2
+ a_CE2_CZ2_CH2
- M_PI
;
957 xi
[atCH2
] = xi
[atCZ2
]+b_CZ2_CH2
*sin(alpha
);
958 yi
[atCH2
] = yi
[atCZ2
]-b_CZ2_CH2
*cos(alpha
);
961 alpha
= a_CE2_CD2_CG
+ a_CD2_CG_CD1
- a_CG_CD1_HD1
;
962 xi
[atHD1
] = xi
[atCD1
]-b_CD1_HD1
*sin(alpha
);
963 yi
[atHD1
] = yi
[atCD1
]+b_CD1_HD1
*cos(alpha
);
965 alpha
= a_NE1_CE2_CD2
+ M_PI
- a_HE1_NE1_CE2
;
966 xi
[atHE1
] = xi
[atNE1
]-b_NE1_HE1
*sin(alpha
);
967 yi
[atHE1
] = yi
[atNE1
]-b_NE1_HE1
*cos(alpha
);
969 alpha
= a_CE2_CD2_CE3
+ M_PI
- a_CD2_CE3_HE3
;
970 xi
[atHE3
] = xi
[atCE3
]+b_CE3_HE3
*sin(alpha
);
971 yi
[atHE3
] = yi
[atCE3
]+b_CE3_HE3
*cos(alpha
);
973 alpha
= a_CD2_CE2_CZ2
+ M_PI
- a_CE2_CZ2_HZ2
;
974 xi
[atHZ2
] = xi
[atCZ2
]+b_CZ2_HZ2
*sin(alpha
);
975 yi
[atHZ2
] = yi
[atCZ2
]-b_CZ2_HZ2
*cos(alpha
);
977 alpha
= a_CD2_CE2_CZ2
+ a_CE2_CZ2_CH2
- a_CZ2_CH2_HH2
;
978 xi
[atHZ3
] = xi
[atCZ3
]+b_CZ3_HZ3
*sin(alpha
);
979 yi
[atHZ3
] = yi
[atCZ3
]+b_CZ3_HZ3
*cos(alpha
);
981 alpha
= a_CE2_CD2_CE3
+ a_CD2_CE3_CZ3
- a_CE3_CZ3_HZ3
;
982 xi
[atHH2
] = xi
[atCH2
]+b_CH2_HH2
*sin(alpha
);
983 yi
[atHH2
] = yi
[atCH2
]-b_CH2_HH2
*cos(alpha
);
985 /* Calculate masses for each ring and put it on the dummy masses */
986 for (j
= 0; j
< NMASS
; j
++)
988 mM
[j
] = xcom
[j
] = ycom
[j
] = 0;
990 for (i
= 0; i
< atNR
; i
++)
994 for (j
= 0; j
< NMASS
; j
++)
996 mM
[j
] += mw
[j
][i
] * at
->atom
[ats
[i
]].m
;
997 xcom
[j
] += xi
[i
] * mw
[j
][i
] * at
->atom
[ats
[i
]].m
;
998 ycom
[j
] += yi
[i
] * mw
[j
][i
] * at
->atom
[ats
[i
]].m
;
1002 for (j
= 0; j
< NMASS
; j
++)
1008 /* get dummy mass type */
1009 tpM
= vsite_nm2type("MW", atype
);
1010 /* make space for 2 masses: shift all atoms starting with CB */
1012 for (j
= 0; j
< NMASS
; j
++)
1014 atM
[j
] = i0
+*nadd
+j
;
1018 fprintf(stderr
, "Inserting %d dummy masses at %d\n", NMASS
, (*o2n
)[i0
]+1);
1021 for (j
= i0
; j
< at
->nr
; j
++)
1023 (*o2n
)[j
] = j
+*nadd
;
1025 srenew(*newx
, at
->nr
+*nadd
);
1026 srenew(*newatom
, at
->nr
+*nadd
);
1027 srenew(*newatomname
, at
->nr
+*nadd
);
1028 srenew(*newvsite_type
, at
->nr
+*nadd
);
1029 srenew(*newcgnr
, at
->nr
+*nadd
);
1030 for (j
= 0; j
< NMASS
; j
++)
1032 (*newatomname
)[at
->nr
+*nadd
-1-j
] = NULL
;
1035 /* Dummy masses will be placed at the center-of-mass in each ring. */
1037 /* calc initial position for dummy masses in real (non-local) coordinates.
1038 * Cheat by using the routine to calculate virtual site parameters. It is
1039 * much easier when we have the coordinates expressed in terms of
1042 rvec_sub(x
[ats
[atCB
]], x
[ats
[atCG
]], r_ij
);
1043 rvec_sub(x
[ats
[atCD2
]], x
[ats
[atCG
]], r_ik
);
1044 calc_vsite3_param(xcom
[0], ycom
[0], xi
[atCG
], yi
[atCG
], xi
[atCB
], yi
[atCB
],
1045 xi
[atCD2
], yi
[atCD2
], &a
, &b
);
1048 rvec_add(t1
, t2
, t1
);
1049 rvec_add(t1
, x
[ats
[atCG
]], (*newx
)[atM
[0]]);
1051 calc_vsite3_param(xcom
[1], ycom
[1], xi
[atCG
], yi
[atCG
], xi
[atCB
], yi
[atCB
],
1052 xi
[atCD2
], yi
[atCD2
], &a
, &b
);
1055 rvec_add(t1
, t2
, t1
);
1056 rvec_add(t1
, x
[ats
[atCG
]], (*newx
)[atM
[1]]);
1058 /* set parameters for the masses */
1059 for (j
= 0; j
< NMASS
; j
++)
1061 sprintf(name
, "MW%d", j
+1);
1062 (*newatomname
) [atM
[j
]] = put_symtab(symtab
, name
);
1063 (*newatom
) [atM
[j
]].m
= (*newatom
)[atM
[j
]].mB
= mM
[j
];
1064 (*newatom
) [atM
[j
]].q
= (*newatom
)[atM
[j
]].qB
= 0.0;
1065 (*newatom
) [atM
[j
]].type
= (*newatom
)[atM
[j
]].typeB
= tpM
;
1066 (*newatom
) [atM
[j
]].ptype
= eptAtom
;
1067 (*newatom
) [atM
[j
]].resind
= at
->atom
[i0
].resind
;
1068 (*newatom
) [atM
[j
]].elem
[0] = 'M';
1069 (*newatom
) [atM
[j
]].elem
[1] = '\0';
1070 (*newvsite_type
)[atM
[j
]] = NOTSET
;
1071 (*newcgnr
) [atM
[j
]] = (*cgnr
)[i0
];
1073 /* renumber cgnr: */
1074 for (i
= i0
; i
< at
->nr
; i
++)
1079 /* constraints between CB, M1 and M2 */
1080 /* 'add_shift' says which atoms won't be renumbered afterwards */
1081 dCBM1
= std::sqrt( sqr(xcom
[0]-xi
[atCB
]) + sqr(ycom
[0]-yi
[atCB
]) );
1082 dM1M2
= std::sqrt( sqr(xcom
[0]-xcom
[1]) + sqr(ycom
[0]-ycom
[1]) );
1083 dCBM2
= std::sqrt( sqr(xcom
[1]-xi
[atCB
]) + sqr(ycom
[1]-yi
[atCB
]) );
1084 my_add_param(&(plist
[F_CONSTRNC
]), ats
[atCB
], add_shift
+atM
[0], dCBM1
);
1085 my_add_param(&(plist
[F_CONSTRNC
]), ats
[atCB
], add_shift
+atM
[1], dCBM2
);
1086 my_add_param(&(plist
[F_CONSTRNC
]), add_shift
+atM
[0], add_shift
+atM
[1], dM1M2
);
1088 /* rest will be vsite3 */
1090 for (i
= 0; i
< atNR
; i
++)
1094 at
->atom
[ats
[i
]].m
= at
->atom
[ats
[i
]].mB
= 0;
1095 (*vsite_type
)[ats
[i
]] = F_VSITE3
;
1100 /* now define all vsites from M1, M2, CB, ie:
1101 r_d = r_M1 + a r_M1_M2 + b r_M1_CB */
1102 for (i
= 0; i
< atNR
; i
++)
1104 if ( (*vsite_type
)[ats
[i
]] == F_VSITE3
)
1106 calc_vsite3_param(xi
[i
], yi
[i
], xcom
[0], ycom
[0], xcom
[1], ycom
[1], xi
[atCB
], yi
[atCB
], &a
, &b
);
1107 add_vsite3_param(&plist
[F_VSITE3
],
1108 ats
[i
], add_shift
+atM
[0], add_shift
+atM
[1], ats
[atCB
], a
, b
);
1116 static int gen_vsites_tyr(gpp_atomtype_t atype
, rvec
*newx
[],
1117 t_atom
*newatom
[], char ***newatomname
[],
1118 int *o2n
[], int *newvsite_type
[], int *newcgnr
[],
1119 t_symtab
*symtab
, int *nadd
, rvec x
[], int *cgnr
[],
1120 t_atoms
*at
, int *vsite_type
[], t_params plist
[],
1121 int nrfound
, int *ats
, int add_shift
,
1122 t_vsitetop
*vsitetop
, int nvsitetop
)
1124 int nvsite
, i
, i0
, j
, atM
, tpM
;
1125 real dCGCE
, dCEOH
, dCGM
, tmp1
, a
, b
;
1126 real bond_cc
, bond_ch
, bond_co
, bond_oh
, angle_coh
;
1132 /* these MUST correspond to the atnms array in do_vsite_aromatics! */
1134 atCG
, atCD1
, atHD1
, atCD2
, atHD2
, atCE1
, atHE1
, atCE2
, atHE2
,
1135 atCZ
, atOH
, atHH
, atNR
1138 /* CG, CE1, CE2 (as in general 6-ring) and OH and HH stay,
1139 rest gets virtualized.
1140 Now we have two linked triangles with one improper keeping them flat */
1141 if (atNR
!= nrfound
)
1143 gmx_incons("Number of atom types in gen_vsites_tyr");
1146 /* Aromatic rings have 6-fold symmetry, so we only need one bond length
1147 * for the ring part (angle is always 120 degrees).
1149 bond_cc
= get_ddb_bond(vsitetop
, nvsitetop
, "TYR", "CD1", "CE1");
1150 bond_ch
= get_ddb_bond(vsitetop
, nvsitetop
, "TYR", "CD1", "HD1");
1151 bond_co
= get_ddb_bond(vsitetop
, nvsitetop
, "TYR", "CZ", "OH");
1152 bond_oh
= get_ddb_bond(vsitetop
, nvsitetop
, "TYR", "OH", "HH");
1153 angle_coh
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, "TYR", "CZ", "OH", "HH");
1155 xi
[atCG
] = -bond_cc
+bond_cc
*cos(ANGLE_6RING
);
1156 xi
[atCD1
] = -bond_cc
;
1157 xi
[atHD1
] = xi
[atCD1
]+bond_ch
*cos(ANGLE_6RING
);
1159 xi
[atHE1
] = xi
[atCE1
]-bond_ch
*cos(ANGLE_6RING
);
1160 xi
[atCD2
] = xi
[atCD1
];
1161 xi
[atHD2
] = xi
[atHD1
];
1162 xi
[atCE2
] = xi
[atCE1
];
1163 xi
[atHE2
] = xi
[atHE1
];
1164 xi
[atCZ
] = bond_cc
*cos(0.5*ANGLE_6RING
);
1165 xi
[atOH
] = xi
[atCZ
]+bond_co
;
1168 for (i
= 0; i
< atOH
; i
++)
1170 xcom
+= xi
[i
]*at
->atom
[ats
[i
]].m
;
1171 mtot
+= at
->atom
[ats
[i
]].m
;
1175 /* first do 6 ring as default,
1176 except CZ (we'll do that different) and HZ (we don't have that): */
1177 nvsite
= gen_vsites_6ring(at
, vsite_type
, plist
, nrfound
, ats
, bond_cc
, bond_ch
, xcom
, FALSE
);
1179 /* then construct CZ from the 2nd triangle */
1180 /* vsite3 construction: r_d = r_i + a r_ij + b r_ik */
1181 a
= b
= 0.5 * bond_co
/ ( bond_co
- bond_cc
*cos(ANGLE_6RING
) );
1182 add_vsite3_param(&plist
[F_VSITE3
],
1183 ats
[atCZ
], ats
[atOH
], ats
[atCE1
], ats
[atCE2
], a
, b
);
1184 at
->atom
[ats
[atCZ
]].m
= at
->atom
[ats
[atCZ
]].mB
= 0;
1186 /* constraints between CE1, CE2 and OH */
1187 dCGCE
= std::sqrt( cosrule(bond_cc
, bond_cc
, ANGLE_6RING
) );
1188 dCEOH
= std::sqrt( cosrule(bond_cc
, bond_co
, ANGLE_6RING
) );
1189 my_add_param(&(plist
[F_CONSTRNC
]), ats
[atCE1
], ats
[atOH
], dCEOH
);
1190 my_add_param(&(plist
[F_CONSTRNC
]), ats
[atCE2
], ats
[atOH
], dCEOH
);
1192 /* We also want to constrain the angle C-O-H, but since CZ is constructed
1193 * we need to introduce a constraint to CG.
1194 * CG is much further away, so that will lead to instabilities in LINCS
1195 * when we constrain both CG-HH and OH-HH distances. Instead of requiring
1196 * the use of lincs_order=8 we introduce a dummy mass three times further
1197 * away from OH than HH. The mass is accordingly a third, with the remaining
1198 * 2/3 moved to OH. This shouldnt cause any problems since the forces will
1199 * apply to the HH constructed atom and not directly on the virtual mass.
1202 vdist
= 2.0*bond_oh
;
1203 mM
= at
->atom
[ats
[atHH
]].m
/2.0;
1204 at
->atom
[ats
[atOH
]].m
+= mM
; /* add 1/2 of original H mass */
1205 at
->atom
[ats
[atOH
]].mB
+= mM
; /* add 1/2 of original H mass */
1206 at
->atom
[ats
[atHH
]].m
= at
->atom
[ats
[atHH
]].mB
= 0;
1208 /* get dummy mass type */
1209 tpM
= vsite_nm2type("MW", atype
);
1210 /* make space for 1 mass: shift HH only */
1215 fprintf(stderr
, "Inserting 1 dummy mass at %d\n", (*o2n
)[i0
]+1);
1218 for (j
= i0
; j
< at
->nr
; j
++)
1220 (*o2n
)[j
] = j
+*nadd
;
1222 srenew(*newx
, at
->nr
+*nadd
);
1223 srenew(*newatom
, at
->nr
+*nadd
);
1224 srenew(*newatomname
, at
->nr
+*nadd
);
1225 srenew(*newvsite_type
, at
->nr
+*nadd
);
1226 srenew(*newcgnr
, at
->nr
+*nadd
);
1227 (*newatomname
)[at
->nr
+*nadd
-1] = NULL
;
1229 /* Calc the dummy mass initial position */
1230 rvec_sub(x
[ats
[atHH
]], x
[ats
[atOH
]], r1
);
1232 rvec_add(r1
, x
[ats
[atHH
]], (*newx
)[atM
]);
1234 strcpy(name
, "MW1");
1235 (*newatomname
) [atM
] = put_symtab(symtab
, name
);
1236 (*newatom
) [atM
].m
= (*newatom
)[atM
].mB
= mM
;
1237 (*newatom
) [atM
].q
= (*newatom
)[atM
].qB
= 0.0;
1238 (*newatom
) [atM
].type
= (*newatom
)[atM
].typeB
= tpM
;
1239 (*newatom
) [atM
].ptype
= eptAtom
;
1240 (*newatom
) [atM
].resind
= at
->atom
[i0
].resind
;
1241 (*newatom
) [atM
].elem
[0] = 'M';
1242 (*newatom
) [atM
].elem
[1] = '\0';
1243 (*newvsite_type
)[atM
] = NOTSET
;
1244 (*newcgnr
) [atM
] = (*cgnr
)[i0
];
1245 /* renumber cgnr: */
1246 for (i
= i0
; i
< at
->nr
; i
++)
1251 (*vsite_type
)[ats
[atHH
]] = F_VSITE2
;
1253 /* assume we also want the COH angle constrained: */
1254 tmp1
= bond_cc
*cos(0.5*ANGLE_6RING
) + dCGCE
*sin(ANGLE_6RING
*0.5) + bond_co
;
1255 dCGM
= std::sqrt( cosrule(tmp1
, vdist
, angle_coh
) );
1256 my_add_param(&(plist
[F_CONSTRNC
]), ats
[atCG
], add_shift
+atM
, dCGM
);
1257 my_add_param(&(plist
[F_CONSTRNC
]), ats
[atOH
], add_shift
+atM
, vdist
);
1259 add_vsite2_param(&plist
[F_VSITE2
],
1260 ats
[atHH
], ats
[atOH
], add_shift
+atM
, 1.0/2.0);
1264 static int gen_vsites_his(t_atoms
*at
, int *vsite_type
[], t_params plist
[],
1265 int nrfound
, int *ats
, t_vsitetop
*vsitetop
, int nvsitetop
)
1268 real a
, b
, alpha
, dCGCE1
, dCGNE2
;
1269 real sinalpha
, cosalpha
;
1270 real xcom
, ycom
, mtot
;
1271 real mG
, mrest
, mCE1
, mNE2
;
1272 real b_CG_ND1
, b_ND1_CE1
, b_CE1_NE2
, b_CG_CD2
, b_CD2_NE2
;
1273 real b_ND1_HD1
, b_NE2_HE2
, b_CE1_HE1
, b_CD2_HD2
;
1274 real a_CG_ND1_CE1
, a_CG_CD2_NE2
, a_ND1_CE1_NE2
, a_CE1_NE2_CD2
;
1275 real a_NE2_CE1_HE1
, a_NE2_CD2_HD2
, a_CE1_ND1_HD1
, a_CE1_NE2_HE2
;
1278 /* these MUST correspond to the atnms array in do_vsite_aromatics! */
1280 atCG
, atND1
, atHD1
, atCD2
, atHD2
, atCE1
, atHE1
, atNE2
, atHE2
, atNR
1282 real x
[atNR
], y
[atNR
];
1284 /* CG, CE1 and NE2 stay, each gets part of the total mass,
1285 rest gets virtualized */
1286 /* check number of atoms, 3 hydrogens may be missing: */
1287 /* assert( nrfound >= atNR-3 || nrfound <= atNR );
1288 * Don't understand the above logic. Shouldn't it be && rather than || ???
1290 if ((nrfound
< atNR
-3) || (nrfound
> atNR
))
1292 gmx_incons("Generating vsites for HIS");
1295 /* avoid warnings about uninitialized variables */
1296 b_ND1_HD1
= b_NE2_HE2
= b_CE1_HE1
= b_CD2_HD2
= a_NE2_CE1_HE1
=
1297 a_NE2_CD2_HD2
= a_CE1_ND1_HD1
= a_CE1_NE2_HE2
= 0;
1299 if (ats
[atHD1
] != NOTSET
)
1301 if (ats
[atHE2
] != NOTSET
)
1303 sprintf(resname
, "HISH");
1307 sprintf(resname
, "HISA");
1312 sprintf(resname
, "HISB");
1315 /* Get geometry from database */
1316 b_CG_ND1
= get_ddb_bond(vsitetop
, nvsitetop
, resname
, "CG", "ND1");
1317 b_ND1_CE1
= get_ddb_bond(vsitetop
, nvsitetop
, resname
, "ND1", "CE1");
1318 b_CE1_NE2
= get_ddb_bond(vsitetop
, nvsitetop
, resname
, "CE1", "NE2");
1319 b_CG_CD2
= get_ddb_bond(vsitetop
, nvsitetop
, resname
, "CG", "CD2");
1320 b_CD2_NE2
= get_ddb_bond(vsitetop
, nvsitetop
, resname
, "CD2", "NE2");
1321 a_CG_ND1_CE1
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, resname
, "CG", "ND1", "CE1");
1322 a_CG_CD2_NE2
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, resname
, "CG", "CD2", "NE2");
1323 a_ND1_CE1_NE2
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, resname
, "ND1", "CE1", "NE2");
1324 a_CE1_NE2_CD2
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, resname
, "CE1", "NE2", "CD2");
1326 if (ats
[atHD1
] != NOTSET
)
1328 b_ND1_HD1
= get_ddb_bond(vsitetop
, nvsitetop
, resname
, "ND1", "HD1");
1329 a_CE1_ND1_HD1
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, resname
, "CE1", "ND1", "HD1");
1331 if (ats
[atHE2
] != NOTSET
)
1333 b_NE2_HE2
= get_ddb_bond(vsitetop
, nvsitetop
, resname
, "NE2", "HE2");
1334 a_CE1_NE2_HE2
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, resname
, "CE1", "NE2", "HE2");
1336 if (ats
[atHD2
] != NOTSET
)
1338 b_CD2_HD2
= get_ddb_bond(vsitetop
, nvsitetop
, resname
, "CD2", "HD2");
1339 a_NE2_CD2_HD2
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, resname
, "NE2", "CD2", "HD2");
1341 if (ats
[atHE1
] != NOTSET
)
1343 b_CE1_HE1
= get_ddb_bond(vsitetop
, nvsitetop
, resname
, "CE1", "HE1");
1344 a_NE2_CE1_HE1
= DEG2RAD
*get_ddb_angle(vsitetop
, nvsitetop
, resname
, "NE2", "CE1", "HE1");
1347 /* constraints between CG, CE1 and NE1 */
1348 dCGCE1
= std::sqrt( cosrule(b_CG_ND1
, b_ND1_CE1
, a_CG_ND1_CE1
) );
1349 dCGNE2
= std::sqrt( cosrule(b_CG_CD2
, b_CD2_NE2
, a_CG_CD2_NE2
) );
1351 my_add_param(&(plist
[F_CONSTRNC
]), ats
[atCG
], ats
[atCE1
], dCGCE1
);
1352 my_add_param(&(plist
[F_CONSTRNC
]), ats
[atCG
], ats
[atNE2
], dCGNE2
);
1353 /* we already have a constraint CE1-NE2, so we don't add it again */
1355 /* calculate the positions in a local frame of reference.
1356 * The x-axis is the line from CG that makes a right angle
1357 * with the bond CE1-NE2, and the y-axis the bond CE1-NE2.
1359 /* First calculate the x-axis intersection with y-axis (=yCE1).
1360 * Get cos(angle CG-CE1-NE2) :
1362 cosalpha
= acosrule(dCGNE2
, dCGCE1
, b_CE1_NE2
);
1364 y
[atCE1
] = cosalpha
*dCGCE1
;
1366 y
[atNE2
] = y
[atCE1
]-b_CE1_NE2
;
1367 sinalpha
= std::sqrt(1-cosalpha
*cosalpha
);
1368 x
[atCG
] = -sinalpha
*dCGCE1
;
1370 x
[atHE1
] = x
[atHE2
] = x
[atHD1
] = x
[atHD2
] = 0;
1371 y
[atHE1
] = y
[atHE2
] = y
[atHD1
] = y
[atHD2
] = 0;
1373 /* calculate ND1 and CD2 positions from CE1 and NE2 */
1375 x
[atND1
] = -b_ND1_CE1
*sin(a_ND1_CE1_NE2
);
1376 y
[atND1
] = y
[atCE1
]-b_ND1_CE1
*cos(a_ND1_CE1_NE2
);
1378 x
[atCD2
] = -b_CD2_NE2
*sin(a_CE1_NE2_CD2
);
1379 y
[atCD2
] = y
[atNE2
]+b_CD2_NE2
*cos(a_CE1_NE2_CD2
);
1381 /* And finally the hydrogen positions */
1382 if (ats
[atHE1
] != NOTSET
)
1384 x
[atHE1
] = x
[atCE1
] + b_CE1_HE1
*sin(a_NE2_CE1_HE1
);
1385 y
[atHE1
] = y
[atCE1
] - b_CE1_HE1
*cos(a_NE2_CE1_HE1
);
1387 /* HD2 - first get (ccw) angle from (positive) y-axis */
1388 if (ats
[atHD2
] != NOTSET
)
1390 alpha
= a_CE1_NE2_CD2
+ M_PI
- a_NE2_CD2_HD2
;
1391 x
[atHD2
] = x
[atCD2
] - b_CD2_HD2
*sin(alpha
);
1392 y
[atHD2
] = y
[atCD2
] + b_CD2_HD2
*cos(alpha
);
1394 if (ats
[atHD1
] != NOTSET
)
1396 /* HD1 - first get (cw) angle from (positive) y-axis */
1397 alpha
= a_ND1_CE1_NE2
+ M_PI
- a_CE1_ND1_HD1
;
1398 x
[atHD1
] = x
[atND1
] - b_ND1_HD1
*sin(alpha
);
1399 y
[atHD1
] = y
[atND1
] - b_ND1_HD1
*cos(alpha
);
1401 if (ats
[atHE2
] != NOTSET
)
1403 x
[atHE2
] = x
[atNE2
] + b_NE2_HE2
*sin(a_CE1_NE2_HE2
);
1404 y
[atHE2
] = y
[atNE2
] + b_NE2_HE2
*cos(a_CE1_NE2_HE2
);
1406 /* Have all coordinates now */
1408 /* calc center-of-mass; keep atoms CG, CE1, NE2 and
1409 * set the rest to vsite3
1411 mtot
= xcom
= ycom
= 0;
1413 for (i
= 0; i
< atNR
; i
++)
1415 if (ats
[i
] != NOTSET
)
1417 mtot
+= at
->atom
[ats
[i
]].m
;
1418 xcom
+= x
[i
]*at
->atom
[ats
[i
]].m
;
1419 ycom
+= y
[i
]*at
->atom
[ats
[i
]].m
;
1420 if (i
!= atCG
&& i
!= atCE1
&& i
!= atNE2
)
1422 at
->atom
[ats
[i
]].m
= at
->atom
[ats
[i
]].mB
= 0;
1423 (*vsite_type
)[ats
[i
]] = F_VSITE3
;
1428 if (nvsite
+3 != nrfound
)
1430 gmx_incons("Generating vsites for HIS");
1436 /* distribute mass so that com stays the same */
1437 mG
= xcom
*mtot
/x
[atCG
];
1439 mCE1
= (ycom
-y
[atNE2
])*mrest
/(y
[atCE1
]-y
[atNE2
]);
1442 at
->atom
[ats
[atCG
]].m
= at
->atom
[ats
[atCG
]].mB
= mG
;
1443 at
->atom
[ats
[atCE1
]].m
= at
->atom
[ats
[atCE1
]].mB
= mCE1
;
1444 at
->atom
[ats
[atNE2
]].m
= at
->atom
[ats
[atNE2
]].mB
= mNE2
;
1447 if (ats
[atHE1
] != NOTSET
)
1449 calc_vsite3_param(x
[atHE1
], y
[atHE1
], x
[atCE1
], y
[atCE1
], x
[atNE2
], y
[atNE2
],
1450 x
[atCG
], y
[atCG
], &a
, &b
);
1451 add_vsite3_param(&plist
[F_VSITE3
],
1452 ats
[atHE1
], ats
[atCE1
], ats
[atNE2
], ats
[atCG
], a
, b
);
1455 if (ats
[atHE2
] != NOTSET
)
1457 calc_vsite3_param(x
[atHE2
], y
[atHE2
], x
[atNE2
], y
[atNE2
], x
[atCE1
], y
[atCE1
],
1458 x
[atCG
], y
[atCG
], &a
, &b
);
1459 add_vsite3_param(&plist
[F_VSITE3
],
1460 ats
[atHE2
], ats
[atNE2
], ats
[atCE1
], ats
[atCG
], a
, b
);
1464 calc_vsite3_param(x
[atND1
], y
[atND1
], x
[atNE2
], y
[atNE2
], x
[atCE1
], y
[atCE1
],
1465 x
[atCG
], y
[atCG
], &a
, &b
);
1466 add_vsite3_param(&plist
[F_VSITE3
],
1467 ats
[atND1
], ats
[atNE2
], ats
[atCE1
], ats
[atCG
], a
, b
);
1470 calc_vsite3_param(x
[atCD2
], y
[atCD2
], x
[atCE1
], y
[atCE1
], x
[atNE2
], y
[atNE2
],
1471 x
[atCG
], y
[atCG
], &a
, &b
);
1472 add_vsite3_param(&plist
[F_VSITE3
],
1473 ats
[atCD2
], ats
[atCE1
], ats
[atNE2
], ats
[atCG
], a
, b
);
1476 if (ats
[atHD1
] != NOTSET
)
1478 calc_vsite3_param(x
[atHD1
], y
[atHD1
], x
[atNE2
], y
[atNE2
], x
[atCE1
], y
[atCE1
],
1479 x
[atCG
], y
[atCG
], &a
, &b
);
1480 add_vsite3_param(&plist
[F_VSITE3
],
1481 ats
[atHD1
], ats
[atNE2
], ats
[atCE1
], ats
[atCG
], a
, b
);
1484 if (ats
[atHD2
] != NOTSET
)
1486 calc_vsite3_param(x
[atHD2
], y
[atHD2
], x
[atCE1
], y
[atCE1
], x
[atNE2
], y
[atNE2
],
1487 x
[atCG
], y
[atCG
], &a
, &b
);
1488 add_vsite3_param(&plist
[F_VSITE3
],
1489 ats
[atHD2
], ats
[atCE1
], ats
[atNE2
], ats
[atCG
], a
, b
);
1494 static gmx_bool
is_vsite(int vsite_type
)
1496 if (vsite_type
== NOTSET
)
1500 switch (abs(vsite_type
) )
1514 static char atomnamesuffix
[] = "1234";
1516 void do_vsites(int nrtp
, t_restp rtp
[], gpp_atomtype_t atype
,
1517 t_atoms
*at
, t_symtab
*symtab
, rvec
*x
[],
1518 t_params plist
[], int *vsite_type
[], int *cgnr
[],
1519 real mHmult
, gmx_bool bVsiteAromatics
,
1522 #define MAXATOMSPERRESIDUE 16
1523 int i
, j
, k
, m
, i0
, ni0
, whatres
, resind
, add_shift
, ftype
, nvsite
, nadd
;
1525 int nrfound
= 0, needed
, nrbonds
, nrHatoms
, Heavy
, nrheavies
, tpM
, tpHeavy
;
1526 int Hatoms
[4], heavies
[4];
1527 gmx_bool bWARNING
, bAddVsiteParam
, bFirstWater
;
1529 gmx_bool
*bResProcessed
;
1530 real mHtot
, mtot
, fact
, fact2
;
1531 rvec rpar
, rperp
, temp
;
1532 char name
[10], tpname
[32], nexttpname
[32], *ch
;
1534 int *o2n
, *newvsite_type
, *newcgnr
, ats
[MAXATOMSPERRESIDUE
];
1537 char ***newatomname
;
1541 int nvsiteconf
, nvsitetop
, cmplength
;
1542 gmx_bool isN
, planarN
, bFound
;
1543 gmx_residuetype_t
*rt
;
1545 t_vsiteconf
*vsiteconflist
;
1546 /* pointer to a list of CH3/NH3/NH2 configuration entries.
1547 * See comments in read_vsite_database. It isnt beautiful,
1548 * but it had to be fixed, and I dont even want to try to
1549 * maintain this part of the code...
1551 t_vsitetop
*vsitetop
;
1552 /* Pointer to a list of geometry (bond/angle) entries for
1553 * residues like PHE, TRP, TYR, HIS, etc., where we need
1554 * to know the geometry to construct vsite aromatics.
1555 * Note that equilibrium geometry isnt necessarily the same
1556 * as the individual bond and angle values given in the
1557 * force field (rings can be strained).
1560 /* if bVsiteAromatics=TRUE do_vsites will specifically convert atoms in
1561 PHE, TRP, TYR and HIS to a construction of virtual sites */
1563 resPHE
, resTRP
, resTYR
, resHIS
, resNR
1565 const char *resnms
[resNR
] = { "PHE", "TRP", "TYR", "HIS" };
1566 /* Amber03 alternative names for termini */
1567 const char *resnmsN
[resNR
] = { "NPHE", "NTRP", "NTYR", "NHIS" };
1568 const char *resnmsC
[resNR
] = { "CPHE", "CTRP", "CTYR", "CHIS" };
1569 /* HIS can be known as HISH, HIS1, HISA, HID, HIE, HIP, etc. too */
1570 gmx_bool bPartial
[resNR
] = { FALSE
, FALSE
, FALSE
, TRUE
};
1571 /* the atnms for every residue MUST correspond to the enums in the
1572 gen_vsites_* (one for each residue) routines! */
1573 /* also the atom names in atnms MUST be in the same order as in the .rtp! */
1574 const char *atnms
[resNR
][MAXATOMSPERRESIDUE
+1] = {
1576 "CD1", "HD1", "CD2", "HD2",
1577 "CE1", "HE1", "CE2", "HE2",
1581 "CD1", "HD1", "CD2",
1582 "NE1", "HE1", "CE2", "CE3", "HE3",
1583 "CZ2", "HZ2", "CZ3", "HZ3",
1584 "CH2", "HH2", NULL
},
1586 "CD1", "HD1", "CD2", "HD2",
1587 "CE1", "HE1", "CE2", "HE2",
1588 "CZ", "OH", "HH", NULL
},
1590 "ND1", "HD1", "CD2", "HD2",
1591 "CE1", "HE1", "NE2", "HE2", NULL
}
1596 printf("Searching for atoms to make virtual sites ...\n");
1597 fprintf(debug
, "# # # VSITES # # #\n");
1600 ndb
= fflib_search_file_end(ffdir
, ".vsd", FALSE
, &db
);
1602 vsiteconflist
= NULL
;
1605 for (f
= 0; f
< ndb
; f
++)
1607 read_vsite_database(db
[f
], &vsiteconflist
, &nvsiteconf
, &vsitetop
, &nvsitetop
);
1615 /* we need a marker for which atoms should *not* be renumbered afterwards */
1616 add_shift
= 10*at
->nr
;
1617 /* make arrays where masses can be inserted into */
1619 snew(newatom
, at
->nr
);
1620 snew(newatomname
, at
->nr
);
1621 snew(newvsite_type
, at
->nr
);
1622 snew(newcgnr
, at
->nr
);
1623 /* make index array to tell where the atoms go to when masses are inserted */
1625 for (i
= 0; i
< at
->nr
; i
++)
1629 /* make index to tell which residues were already processed */
1630 snew(bResProcessed
, at
->nres
);
1632 gmx_residuetype_init(&rt
);
1634 /* generate vsite constructions */
1635 /* loop over all atoms */
1637 for (i
= 0; (i
< at
->nr
); i
++)
1639 if (at
->atom
[i
].resind
!= resind
)
1641 resind
= at
->atom
[i
].resind
;
1642 resnm
= *(at
->resinfo
[resind
].name
);
1644 /* first check for aromatics to virtualize */
1645 /* don't waste our effort on DNA, water etc. */
1646 /* Only do the vsite aromatic stuff when we reach the
1647 * CA atom, since there might be an X2/X3 group on the
1648 * N-terminus that must be treated first.
1650 if (bVsiteAromatics
&&
1651 !strcmp(*(at
->atomname
[i
]), "CA") &&
1652 !bResProcessed
[resind
] &&
1653 gmx_residuetype_is_protein(rt
, *(at
->resinfo
[resind
].name
)) )
1655 /* mark this residue */
1656 bResProcessed
[resind
] = TRUE
;
1657 /* find out if this residue needs converting */
1659 for (j
= 0; j
< resNR
&& whatres
== NOTSET
; j
++)
1662 cmplength
= bPartial
[j
] ? strlen(resnm
)-1 : strlen(resnm
);
1664 bFound
= ((gmx_strncasecmp(resnm
, resnms
[j
], cmplength
) == 0) ||
1665 (gmx_strncasecmp(resnm
, resnmsN
[j
], cmplength
) == 0) ||
1666 (gmx_strncasecmp(resnm
, resnmsC
[j
], cmplength
) == 0));
1671 /* get atoms we will be needing for the conversion */
1673 for (k
= 0; atnms
[j
][k
]; k
++)
1676 for (m
= i
; m
< at
->nr
&& at
->atom
[m
].resind
== resind
&& ats
[k
] == NOTSET
; m
++)
1678 if (gmx_strcasecmp(*(at
->atomname
[m
]), atnms
[j
][k
]) == 0)
1686 /* now k is number of atom names in atnms[j] */
1695 if (nrfound
< needed
)
1697 gmx_fatal(FARGS
, "not enough atoms found (%d, need %d) in "
1698 "residue %s %d while\n "
1699 "generating aromatics virtual site construction",
1700 nrfound
, needed
, resnm
, at
->resinfo
[resind
].nr
);
1702 /* Advance overall atom counter */
1706 /* the enums for every residue MUST correspond to atnms[residue] */
1712 fprintf(stderr
, "PHE at %d\n", o2n
[ats
[0]]+1);
1714 nvsite
+= gen_vsites_phe(at
, vsite_type
, plist
, nrfound
, ats
, vsitetop
, nvsitetop
);
1719 fprintf(stderr
, "TRP at %d\n", o2n
[ats
[0]]+1);
1721 nvsite
+= gen_vsites_trp(atype
, &newx
, &newatom
, &newatomname
, &o2n
,
1722 &newvsite_type
, &newcgnr
, symtab
, &nadd
, *x
, cgnr
,
1723 at
, vsite_type
, plist
, nrfound
, ats
, add_shift
, vsitetop
, nvsitetop
);
1728 fprintf(stderr
, "TYR at %d\n", o2n
[ats
[0]]+1);
1730 nvsite
+= gen_vsites_tyr(atype
, &newx
, &newatom
, &newatomname
, &o2n
,
1731 &newvsite_type
, &newcgnr
, symtab
, &nadd
, *x
, cgnr
,
1732 at
, vsite_type
, plist
, nrfound
, ats
, add_shift
, vsitetop
, nvsitetop
);
1737 fprintf(stderr
, "HIS at %d\n", o2n
[ats
[0]]+1);
1739 nvsite
+= gen_vsites_his(at
, vsite_type
, plist
, nrfound
, ats
, vsitetop
, nvsitetop
);
1742 /* this means this residue won't be processed */
1745 gmx_fatal(FARGS
, "DEATH HORROR in do_vsites (%s:%d)",
1746 __FILE__
, __LINE__
);
1747 } /* switch whatres */
1748 /* skip back to beginning of residue */
1749 while (i
> 0 && at
->atom
[i
-1].resind
== resind
)
1753 } /* if bVsiteAromatics & is protein */
1755 /* now process the rest of the hydrogens */
1756 /* only process hydrogen atoms which are not already set */
1757 if ( ((*vsite_type
)[i
] == NOTSET
) && is_hydrogen(*(at
->atomname
[i
])))
1759 /* find heavy atom, count #bonds from it and #H atoms bound to it
1760 and return H atom numbers (Hatoms) and heavy atom numbers (heavies) */
1761 count_bonds(i
, &plist
[F_BONDS
], at
->atomname
,
1762 &nrbonds
, &nrHatoms
, Hatoms
, &Heavy
, &nrheavies
, heavies
);
1763 /* get Heavy atom type */
1764 tpHeavy
= get_atype(Heavy
, at
, nrtp
, rtp
, rt
);
1765 strcpy(tpname
, get_atomtype_name(tpHeavy
, atype
));
1768 bAddVsiteParam
= TRUE
;
1769 /* nested if's which check nrHatoms, nrbonds and atomname */
1775 (*vsite_type
)[i
] = F_BONDS
;
1777 case 3: /* =CH-, -NH- or =NH+- */
1778 (*vsite_type
)[i
] = F_VSITE3FD
;
1780 case 4: /* --CH- (tert) */
1781 /* The old type 4FD had stability issues, so
1782 * all new constructs should use 4FDN
1784 (*vsite_type
)[i
] = F_VSITE4FDN
;
1786 /* Check parity of heavy atoms from coordinates */
1791 rvec_sub((*x
)[aj
], (*x
)[ai
], tmpmat
[0]);
1792 rvec_sub((*x
)[ak
], (*x
)[ai
], tmpmat
[1]);
1793 rvec_sub((*x
)[al
], (*x
)[ai
], tmpmat
[2]);
1795 if (det(tmpmat
) > 0)
1803 default: /* nrbonds != 2, 3 or 4 */
1808 else if ( /*(nrHatoms == 2) && (nrbonds == 2) && REMOVED this test
1810 (gmx_strncasecmp(*at
->atomname
[Heavy
], "OW", 2) == 0) )
1812 bAddVsiteParam
= FALSE
; /* this is water: skip these hydrogens */
1815 bFirstWater
= FALSE
;
1819 "Not converting hydrogens in water to virtual sites\n");
1823 else if ( (nrHatoms
== 2) && (nrbonds
== 4) )
1825 /* -CH2- , -NH2+- */
1826 (*vsite_type
)[Hatoms
[0]] = F_VSITE3OUT
;
1827 (*vsite_type
)[Hatoms
[1]] = -F_VSITE3OUT
;
1831 /* 2 or 3 hydrogen atom, with 3 or 4 bonds in total to the heavy atom.
1832 * If it is a nitrogen, first check if it is planar.
1834 isN
= planarN
= FALSE
;
1835 if ((nrHatoms
== 2) && ((*at
->atomname
[Heavy
])[0] == 'N'))
1838 j
= nitrogen_is_planar(vsiteconflist
, nvsiteconf
, tpname
);
1841 gmx_fatal(FARGS
, "No vsite database NH2 entry for type %s\n", tpname
);
1845 if ( (nrHatoms
== 2) && (nrbonds
== 3) && ( !isN
|| planarN
) )
1847 /* =CH2 or, if it is a nitrogen NH2, it is a planar one */
1848 (*vsite_type
)[Hatoms
[0]] = F_VSITE3FAD
;
1849 (*vsite_type
)[Hatoms
[1]] = -F_VSITE3FAD
;
1851 else if ( ( (nrHatoms
== 2) && (nrbonds
== 3) &&
1852 ( isN
&& !planarN
) ) ||
1853 ( (nrHatoms
== 3) && (nrbonds
== 4) ) )
1855 /* CH3, NH3 or non-planar NH2 group */
1856 int Hat_vsite_type
[3] = { F_VSITE3
, F_VSITE3OUT
, F_VSITE3OUT
};
1857 gmx_bool Hat_SwapParity
[3] = { FALSE
, TRUE
, FALSE
};
1861 fprintf(stderr
, "-XH3 or nonplanar NH2 group at %d\n", i
+1);
1863 bAddVsiteParam
= FALSE
; /* we'll do this ourselves! */
1864 /* -NH2 (umbrella), -NH3+ or -CH3 */
1865 (*vsite_type
)[Heavy
] = F_VSITE3
;
1866 for (j
= 0; j
< nrHatoms
; j
++)
1868 (*vsite_type
)[Hatoms
[j
]] = Hat_vsite_type
[j
];
1870 /* get dummy mass type from first char of heavy atom type (N or C) */
1872 strcpy(nexttpname
, get_atomtype_name(get_atype(heavies
[0], at
, nrtp
, rtp
, rt
), atype
));
1873 ch
= get_dummymass_name(vsiteconflist
, nvsiteconf
, tpname
, nexttpname
);
1879 gmx_fatal(FARGS
, "Can't find dummy mass for type %s bonded to type %s in the virtual site database (.vsd files). Add it to the database!\n", tpname
, nexttpname
);
1883 gmx_fatal(FARGS
, "A dummy mass for type %s bonded to type %s is required, but no virtual site database (.vsd) files where found.\n", tpname
, nexttpname
);
1891 tpM
= vsite_nm2type(name
, atype
);
1892 /* make space for 2 masses: shift all atoms starting with 'Heavy' */
1898 fprintf(stderr
, "Inserting %d dummy masses at %d\n", NMASS
, o2n
[i0
]+1);
1901 for (j
= i0
; j
< at
->nr
; j
++)
1906 srenew(newx
, at
->nr
+nadd
);
1907 srenew(newatom
, at
->nr
+nadd
);
1908 srenew(newatomname
, at
->nr
+nadd
);
1909 srenew(newvsite_type
, at
->nr
+nadd
);
1910 srenew(newcgnr
, at
->nr
+nadd
);
1912 for (j
= 0; j
< NMASS
; j
++)
1914 newatomname
[at
->nr
+nadd
-1-j
] = NULL
;
1917 /* calculate starting position for the masses */
1919 /* get atom masses, and set Heavy and Hatoms mass to zero */
1920 for (j
= 0; j
< nrHatoms
; j
++)
1922 mHtot
+= get_amass(Hatoms
[j
], at
, nrtp
, rtp
, rt
);
1923 at
->atom
[Hatoms
[j
]].m
= at
->atom
[Hatoms
[j
]].mB
= 0;
1925 mtot
= mHtot
+ get_amass(Heavy
, at
, nrtp
, rtp
, rt
);
1926 at
->atom
[Heavy
].m
= at
->atom
[Heavy
].mB
= 0;
1932 fact
= std::sqrt(fact2
);
1933 /* generate vectors parallel and perpendicular to rotational axis:
1934 * rpar = Heavy -> Hcom
1935 * rperp = Hcom -> H1 */
1937 for (j
= 0; j
< nrHatoms
; j
++)
1939 rvec_inc(rpar
, (*x
)[Hatoms
[j
]]);
1941 svmul(1.0/nrHatoms
, rpar
, rpar
); /* rpar = ( H1+H2+H3 ) / 3 */
1942 rvec_dec(rpar
, (*x
)[Heavy
]); /* - Heavy */
1943 rvec_sub((*x
)[Hatoms
[0]], (*x
)[Heavy
], rperp
);
1944 rvec_dec(rperp
, rpar
); /* rperp = H1 - Heavy - rpar */
1945 /* calc mass positions */
1946 svmul(fact2
, rpar
, temp
);
1947 for (j
= 0; (j
< NMASS
); j
++) /* xM = xN + fact2 * rpar +/- fact * rperp */
1949 rvec_add((*x
)[Heavy
], temp
, newx
[ni0
+j
]);
1951 svmul(fact
, rperp
, temp
);
1952 rvec_inc(newx
[ni0
], temp
);
1953 rvec_dec(newx
[ni0
+1], temp
);
1954 /* set atom parameters for the masses */
1955 for (j
= 0; (j
< NMASS
); j
++)
1957 /* make name: "M??#" or "M?#" (? is atomname, # is number) */
1959 for (k
= 0; (*at
->atomname
[Heavy
])[k
] && ( k
< NMASS
); k
++)
1961 name
[k
+1] = (*at
->atomname
[Heavy
])[k
];
1963 name
[k
+1] = atomnamesuffix
[j
];
1965 newatomname
[ni0
+j
] = put_symtab(symtab
, name
);
1966 newatom
[ni0
+j
].m
= newatom
[ni0
+j
].mB
= mtot
/NMASS
;
1967 newatom
[ni0
+j
].q
= newatom
[ni0
+j
].qB
= 0.0;
1968 newatom
[ni0
+j
].type
= newatom
[ni0
+j
].typeB
= tpM
;
1969 newatom
[ni0
+j
].ptype
= eptAtom
;
1970 newatom
[ni0
+j
].resind
= at
->atom
[i0
].resind
;
1971 newatom
[ni0
+j
].elem
[0] = 'M';
1972 newatom
[ni0
+j
].elem
[1] = '\0';
1973 newvsite_type
[ni0
+j
] = NOTSET
;
1974 newcgnr
[ni0
+j
] = (*cgnr
)[i0
];
1976 /* add constraints between dummy masses and to heavies[0] */
1977 /* 'add_shift' says which atoms won't be renumbered afterwards */
1978 my_add_param(&(plist
[F_CONSTRNC
]), heavies
[0], add_shift
+ni0
, NOTSET
);
1979 my_add_param(&(plist
[F_CONSTRNC
]), heavies
[0], add_shift
+ni0
+1, NOTSET
);
1980 my_add_param(&(plist
[F_CONSTRNC
]), add_shift
+ni0
, add_shift
+ni0
+1, NOTSET
);
1982 /* generate Heavy, H1, H2 and H3 from M1, M2 and heavies[0] */
1983 /* note that vsite_type cannot be NOTSET, because we just set it */
1984 add_vsite3_atoms (&plist
[(*vsite_type
)[Heavy
]],
1985 Heavy
, heavies
[0], add_shift
+ni0
, add_shift
+ni0
+1,
1987 for (j
= 0; j
< nrHatoms
; j
++)
1989 add_vsite3_atoms(&plist
[(*vsite_type
)[Hatoms
[j
]]],
1990 Hatoms
[j
], heavies
[0], add_shift
+ni0
, add_shift
+ni0
+1,
2004 "Warning: cannot convert atom %d %s (bound to a heavy atom "
2006 " %d bonds and %d bound hydrogens atoms) to virtual site\n",
2007 i
+1, *(at
->atomname
[i
]), tpname
, nrbonds
, nrHatoms
);
2011 /* add vsite parameters to topology,
2012 also get rid of negative vsite_types */
2013 add_vsites(plist
, (*vsite_type
), Heavy
, nrHatoms
, Hatoms
,
2014 nrheavies
, heavies
);
2015 /* transfer mass of virtual site to Heavy atom */
2016 for (j
= 0; j
< nrHatoms
; j
++)
2018 if (is_vsite((*vsite_type
)[Hatoms
[j
]]))
2020 at
->atom
[Heavy
].m
+= at
->atom
[Hatoms
[j
]].m
;
2021 at
->atom
[Heavy
].mB
= at
->atom
[Heavy
].m
;
2022 at
->atom
[Hatoms
[j
]].m
= at
->atom
[Hatoms
[j
]].mB
= 0;
2029 fprintf(debug
, "atom %d: ", o2n
[i
]+1);
2030 print_bonds(debug
, o2n
, nrHatoms
, Hatoms
, Heavy
, nrheavies
, heavies
);
2032 } /* if vsite NOTSET & is hydrogen */
2034 } /* for i < at->nr */
2036 gmx_residuetype_destroy(rt
);
2040 fprintf(debug
, "Before inserting new atoms:\n");
2041 for (i
= 0; i
< at
->nr
; i
++)
2043 fprintf(debug
, "%4d %4d %4s %4d %4s %6d %-10s\n", i
+1, o2n
[i
]+1,
2044 at
->atomname
[i
] ? *(at
->atomname
[i
]) : "(NULL)",
2045 at
->resinfo
[at
->atom
[i
].resind
].nr
,
2046 at
->resinfo
[at
->atom
[i
].resind
].name
?
2047 *(at
->resinfo
[at
->atom
[i
].resind
].name
) : "(NULL)",
2049 ((*vsite_type
)[i
] == NOTSET
) ?
2050 "NOTSET" : interaction_function
[(*vsite_type
)[i
]].name
);
2052 fprintf(debug
, "new atoms to be inserted:\n");
2053 for (i
= 0; i
< at
->nr
+nadd
; i
++)
2057 fprintf(debug
, "%4d %4s %4d %6d %-10s\n", i
+1,
2058 newatomname
[i
] ? *(newatomname
[i
]) : "(NULL)",
2059 newatom
[i
].resind
, newcgnr
[i
],
2060 (newvsite_type
[i
] == NOTSET
) ?
2061 "NOTSET" : interaction_function
[newvsite_type
[i
]].name
);
2066 /* add all original atoms to the new arrays, using o2n index array */
2067 for (i
= 0; i
< at
->nr
; i
++)
2069 newatomname
[o2n
[i
]] = at
->atomname
[i
];
2070 newatom
[o2n
[i
]] = at
->atom
[i
];
2071 newvsite_type
[o2n
[i
]] = (*vsite_type
)[i
];
2072 newcgnr
[o2n
[i
]] = (*cgnr
) [i
];
2073 copy_rvec((*x
)[i
], newx
[o2n
[i
]]);
2075 /* throw away old atoms */
2077 sfree(at
->atomname
);
2081 /* put in the new ones */
2084 at
->atomname
= newatomname
;
2085 *vsite_type
= newvsite_type
;
2088 if (at
->nr
> add_shift
)
2090 gmx_fatal(FARGS
, "Added impossible amount of dummy masses "
2091 "(%d on a total of %d atoms)\n", nadd
, at
->nr
-nadd
);
2096 fprintf(debug
, "After inserting new atoms:\n");
2097 for (i
= 0; i
< at
->nr
; i
++)
2099 fprintf(debug
, "%4d %4s %4d %4s %6d %-10s\n", i
+1,
2100 at
->atomname
[i
] ? *(at
->atomname
[i
]) : "(NULL)",
2101 at
->resinfo
[at
->atom
[i
].resind
].nr
,
2102 at
->resinfo
[at
->atom
[i
].resind
].name
?
2103 *(at
->resinfo
[at
->atom
[i
].resind
].name
) : "(NULL)",
2105 ((*vsite_type
)[i
] == NOTSET
) ?
2106 "NOTSET" : interaction_function
[(*vsite_type
)[i
]].name
);
2110 /* now renumber all the interactions because of the added atoms */
2111 for (ftype
= 0; ftype
< F_NRE
; ftype
++)
2113 params
= &(plist
[ftype
]);
2116 fprintf(debug
, "Renumbering %d %s\n", params
->nr
,
2117 interaction_function
[ftype
].longname
);
2119 for (i
= 0; i
< params
->nr
; i
++)
2121 for (j
= 0; j
< NRAL(ftype
); j
++)
2123 if (params
->param
[i
].a
[j
] >= add_shift
)
2127 fprintf(debug
, " [%d -> %d]", params
->param
[i
].a
[j
],
2128 params
->param
[i
].a
[j
]-add_shift
);
2130 params
->param
[i
].a
[j
] = params
->param
[i
].a
[j
]-add_shift
;
2136 fprintf(debug
, " [%d -> %d]", params
->param
[i
].a
[j
],
2137 o2n
[params
->param
[i
].a
[j
]]);
2139 params
->param
[i
].a
[j
] = o2n
[params
->param
[i
].a
[j
]];
2144 fprintf(debug
, "\n");
2148 /* now check if atoms in the added constraints are in increasing order */
2149 params
= &(plist
[F_CONSTRNC
]);
2150 for (i
= 0; i
< params
->nr
; i
++)
2152 if (params
->param
[i
].ai() > params
->param
[i
].aj())
2154 j
= params
->param
[i
].aj();
2155 params
->param
[i
].aj() = params
->param
[i
].ai();
2156 params
->param
[i
].ai() = j
;
2163 /* tell the user what we did */
2164 fprintf(stderr
, "Marked %d virtual sites\n", nvsite
);
2165 fprintf(stderr
, "Added %d dummy masses\n", nadd
);
2166 fprintf(stderr
, "Added %d new constraints\n", plist
[F_CONSTRNC
].nr
);
2169 void do_h_mass(t_params
*psb
, int vsite_type
[], t_atoms
*at
, real mHmult
,
2170 gmx_bool bDeuterate
)
2174 /* loop over all atoms */
2175 for (i
= 0; i
< at
->nr
; i
++)
2177 /* adjust masses if i is hydrogen and not a virtual site */
2178 if (!is_vsite(vsite_type
[i
]) && is_hydrogen(*(at
->atomname
[i
])) )
2180 /* find bonded heavy atom */
2182 for (j
= 0; (j
< psb
->nr
) && (a
== NOTSET
); j
++)
2184 /* if other atom is not a virtual site, it is the one we want */
2185 if ( (psb
->param
[j
].ai() == i
) &&
2186 !is_vsite(vsite_type
[psb
->param
[j
].aj()]) )
2188 a
= psb
->param
[j
].aj();
2190 else if ( (psb
->param
[j
].aj() == i
) &&
2191 !is_vsite(vsite_type
[psb
->param
[j
].ai()]) )
2193 a
= psb
->param
[j
].ai();
2198 gmx_fatal(FARGS
, "Unbound hydrogen atom (%d) found while adjusting mass",
2202 /* adjust mass of i (hydrogen) with mHmult
2203 and correct mass of a (bonded atom) with same amount */
2206 at
->atom
[a
].m
-= (mHmult
-1.0)*at
->atom
[i
].m
;
2207 at
->atom
[a
].mB
-= (mHmult
-1.0)*at
->atom
[i
].m
;
2209 at
->atom
[i
].m
*= mHmult
;
2210 at
->atom
[i
].mB
*= mHmult
;