2 * This source file is part of the Alexandria Chemistry Toolkit.
4 * Copyright (C) 2014-2020
7 * Mohammad Mehdi Ghahremanpour,
9 * David van der Spoel (Project leader)
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program 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
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
28 * Implements part of the alexandria program.
29 * \author Mohammad Mehdi Ghahremanpour <mohammad.ghahremanpour@icm.uu.se>
30 * \author David van der Spoel <david.vanderspoel@icm.uu.se>
40 #include "gromacs/utility/stringutil.h"
42 #include "chargemodel.h"
43 #include "poldata_low.h"
44 #include "stringutil.h"
46 /* This source code file is part of the Alexandria project */
60 * Set the file name gentop.dat
63 void setFilename(const std::string
&fn2
);
66 * Set the force field version
67 * \param[in] version Force field version
69 void setVersion(const std::string
&version
)
71 alexandriaVersion_
= version
;
75 * Get the force field version
76 * \return Force field version
78 const std::string
&getVersion() const
80 return alexandriaVersion_
;
84 * Set the potential energy function for VDW interaction.
85 * The VDW potentials supported by Alexandria are LJ, Buckingham, and Wang_Buckingham.
87 * \param[in] func The name of the VDW potential function
89 void setVdwFunction(const std::string
&func
);
92 * Set the combination rule
95 void setCombinationRule(const std::string
&func
);
98 * Set relative dielectric constant
101 void setEpsilonR(double epsilonR
) { gtEpsilonR_
= epsilonR
; }
104 * Set the number of exclusion
106 void setNexcl(int nexcl
) { nexcl_
= nexcl
; }
109 * Add the atom types used in Alexandria FF
111 **\param[in] elem The element of the atom type
112 **\param[in] desc The description of the atom type
113 **\param[in] atype The atom type defined for this element in Alexandria FF
114 **\param[in] ptype The polarizability type defined for this element in Alexandria FF
115 **\param[in] btype The bond type defined for elem in Alexandria FF
116 **\param[in] ztype The zeta type defined for elem in Alexandria FF
117 **\param[in] fixvdw Are these parameters mutable?
118 **\param[in] vdwparams The VDW parameters for elem in Alexandria FF. The number of VDW parameters is 2 for LJ and 3 for
119 * Buckingham and Wang_Buckingham potentials
120 **\param[in] ref_enthalpy The reference enthalpy for elem
122 void addAtype(const std::string
&elem
,
123 const std::string
&desc
,
124 const std::string
&atype
,
125 const std::string
&ptype
,
126 const std::string
&btype
,
127 const std::string
&ztype
,
129 std::string
&vdwparams
,
130 const std::string
&ref_enthalpy
);
133 * Add the polarizability types
135 **\param[in] ptype The name specifying the polarizability type in Alexandria FF
136 **\param[in] miller Miller polarizability type
137 **\param[in] bosque Bosque polarizability type
138 **\param[in] polarizability The calulated value of polarizability
139 **\param[in] sigPol The uncertainty of the calculated polarizability
141 void addPtype(const std::string
&ptype
,
142 const std::string
&miller
,
143 const std::string
&bosque
,
144 double polarizability
,
147 void addVsite(const std::string
&atype
,
148 const std::string
&type
,
155 * Set the value and the associated error for the given poltype
157 **\param[in] ptype Polarizabilty type
158 **\param[in] polarizability The value of polarizabilty
159 **\param[in] sigPol The error
161 bool setPtypePolarizability(const std::string
&ptype
,
162 double polarizability
,
166 * Set the unit of polarizability.
168 void setPolarUnit(const std::string
&polarUnit
)
170 alexandriaPolarUnit_
= polarUnit
;
174 * Set the reference polarizability value.
176 void setPolarRef(const std::string
&polarRef
)
178 alexandriaPolarRef_
= polarRef
;
182 * Set the vsite angle unit.
184 void setVsite_angle_unit(const std::string
&angle_unit
)
186 vsite_angle_unit_
= angle_unit
;
190 * Set the vsite angle unit.
192 void setVsite_length_unit(const std::string
&length_unit
)
194 vsite_length_unit_
= length_unit
;
197 std::vector
<Vsite
> &getVsite() {return vsite_
; }
199 int getVdwFtype() const { return gtVdwFtype_
; }
201 int getNexcl() const { return nexcl_
; }
203 size_t getNatypes() const { return alexandria_
.size(); }
205 size_t getNptypes() const { return ptype_
.size(); }
208 * Return the reference enthalpy for the given atom type
210 **\param[in] atype Atom type
211 **\param[ou] Href Reference enthalpy
213 bool getAtypeRefEnthalpy(const std::string
&atype
,
217 * Return the combination rule
220 const std::string
&getCombinationRule() const { return gtCombinationRule_
; }
223 * Return the combination rule.
225 int getCombRule() const { return gtCombRule_
; }
228 * Return the relative dielectric constant
230 double getEpsilonR() const { return gtEpsilonR_
; }
232 std::string
getGeometry(std::string gtBrule
);
235 * Return the discription corresponding to the atom type
237 * \param[in] atype Atom Type
239 const std::string
&getDesc(const std::string
&atype
) const;
242 * Return the element name corresponding to the atom type
244 * \param[in] atype Atom Type
246 const std::string
&getElem(const std::string
&atype
) const;
249 * Return the element name corresponding to the zeta type
251 * \param[in] ztype zeta Type
253 const std::string
&ztype2elem(const std::string
&ztype
) const;
255 std::vector
<std::string
> ztype_names() const;
258 * Return the charge corresponding to the atyom type
259 * from the gentop.dat file
261 * \param[in] atype Atom type
263 std::string
getCharge( std::string atype
);
265 std::vector
<Ffatype
> &getAtypes() {return alexandria_
; }
267 FfatypeIterator
getAtypeBegin() { return alexandria_
.begin(); }
269 FfatypeIterator
getAtypeEnd() { return alexandria_
.end(); }
271 FfatypeConstIterator
getAtypeBegin() const { return alexandria_
.begin(); }
273 FfatypeConstIterator
getAtypeEnd() const { return alexandria_
.end(); }
276 * Return the iterator corresponding to the atom type
278 * \param[in] atype Atom Type
280 FfatypeIterator
findAtype(const std::string
&atype
)
282 return std::find_if(alexandria_
.begin(), alexandria_
.end(),
283 [atype
](Ffatype
const &f
)
284 { return (atype
== f
.getType()); });
288 * Return the const_iterator corresponding to the atom type
290 * \param[in] atype Atom Type
292 FfatypeConstIterator
findAtype(const std::string
&atype
) const
294 return std::find_if(alexandria_
.begin(), alexandria_
.end(),
295 [atype
](Ffatype
const &f
)
296 { return (atype
== f
.getType()); });
300 * Return the atom type corresponding to the bond type
302 * \param[in] btype Bond Type
304 FfatypeIterator
btypeToAtype(const std::string
&btype
)
306 return std::find_if(alexandria_
.begin(), alexandria_
.end(),
307 [btype
](Ffatype
const &f
)
308 { return (btype
== f
.getBtype()); });
312 * Return true if a given bond type exists in Alexandria
314 * \param[in] btype Bond Type
316 bool haveBtype(const std::string
&btype
)
318 return (btypeToAtype(btype
) != alexandria_
.end());
322 * Return the atom type corresponding to the polarizability type
324 * \param[in] ptype Polarizability Type
326 FfatypeConstIterator
ptypeToAtype(const std::string
&ptype
) const
328 return std::find_if(alexandria_
.begin(), alexandria_
.end(),
329 [ptype
](Ffatype
const &f
)
330 { return (ptype
== f
.getPtype()); });
333 PtypeConstIterator
getPtypeBegin() const { return ptype_
.begin(); }
335 PtypeConstIterator
getPtypeEnd() const { return ptype_
.end(); }
337 VsiteIterator
getVsiteBegin() { return vsite_
.begin(); }
339 VsiteConstIterator
getVsiteBegin() const { return vsite_
.begin(); }
341 VsiteIterator
getVsiteEnd() { return vsite_
.end(); }
343 VsiteConstIterator
getVsiteEnd() const { return vsite_
.end(); }
345 VsiteIterator
findVsite(std::string atype
)
348 return std::find_if(vsite_
.begin(), vsite_
.end(),
349 [atype
](const Vsite
&vs
)
351 return (atype
== vs
.atype());
355 VsiteConstIterator
findVsite(std::string atype
) const
358 return std::find_if(vsite_
.begin(), vsite_
.end(),
359 [atype
](const Vsite
&vs
)
361 return (atype
== vs
.atype());
366 * Return the iterator corresponding to the polarizability type
368 * \param[in] ptype Polarizability Type
370 PtypeIterator
findPtype(const std::string
&ptype
)
372 return std::find_if(ptype_
.begin(), ptype_
.end(),
373 [ptype
](Ptype
const &p
)
374 { return (ptype
== p
.getType()); });
379 * Return the poltype corresponding to atype and true if successful
381 * \param[in] atype Atom type
382 * \param[out] ptype Polarizability type.
384 bool atypeToPtype(const std::string
&atype
,
385 std::string
&ptype
) const;
388 * Return the poltype corresponding to ztype and true if successful
390 * \param[in] ztype Zeta type
391 * \param[out] ptype Polarizability type.
393 bool ztypeToPtype(const std::string
&ztype
,
394 std::string
&ptype
) const;
397 * Return the bond type corresponding to atom type and true if successful
399 * \param[in] atype Atom type
400 * \param[out] btype Polarizability type.
402 bool atypeToBtype(const std::string
&atype
,
403 std::string
&btype
) const;
406 /* Return 1 if OK, 0 if not found */
407 bool getPtypePol(const std::string
&ptype
,
408 double *polarizability
,
409 double *sigPol
) const;
411 bool getAtypePol(const std::string
&atype
,
412 double *polarizability
,
413 double *sigPol
) const;
415 bool getZtypePol(const std::string
&ztype
,
416 double *polarizability
,
417 double *sigPol
) const;
419 void addMiller(const std::string
&miller
,
423 const std::string
&alexandria_equiv
);
425 /* Return true if "miller" was found */
426 bool getMillerPol(const std::string
&miller
,
430 std::string
&alexandria_equiv
) const;
432 MillerIterator
getMillerBegin() { return miller_
.begin(); }
434 MillerIterator
getMillerEnd() { return miller_
.end(); }
436 MillerConstIterator
getMillerBegin() const { return miller_
.begin(); }
438 MillerConstIterator
getMillerEnd() const { return miller_
.end(); }
440 void setMillerFlags(const std::string
&tauUnit
,
441 const std::string
&ahpUnit
,
442 const std::string
&ref
)
444 millerTauUnit_
= tauUnit
;
445 millerAhpUnit_
= ahpUnit
;
449 void getMillerFlags(std::string
&tauUnit
,
450 std::string
&ahpUnit
,
451 std::string
&ref
) const
453 tauUnit
= millerTauUnit_
;
454 ahpUnit
= millerAhpUnit_
;
459 * Convert poltype to miller name. Return true if found
461 bool ptypeToMiller(const std::string
&ptype
,
462 std::string
&mil_type
) const;
464 void addBosque(const std::string
&bosque
,
465 double polarizability
)
467 Bosque
bos(bosque
, polarizability
);
468 bosque_
.push_back(bos
);
471 BosqueIterator
getBosqueBegin() { return bosque_
.begin(); }
473 BosqueIterator
getBosqueEnd() { return bosque_
.end(); }
475 BosqueConstIterator
getBosqueBegin() const { return bosque_
.begin(); }
477 BosqueConstIterator
getBosqueEnd() const { return bosque_
.end(); }
479 void setBosqueFlags(const std::string
&polarUnit
,
480 const std::string
&ref
)
482 bosquePolarUnit_
= polarUnit
;
486 void getBosqueFlags(std::string
&polarUnit
,
487 std::string
&ref
) const
489 polarUnit
= bosquePolarUnit_
;
494 * Convert poltype to bosque name. Return true if found.
496 bool ptypeToBosque(const std::string
&ptype
,
497 std::string
&bosque
) const;
499 bool getBosquePol(const std::string
&bosque
,
500 double *polarizability
) const;
502 /* Return true on success or false otherwise */
505 * Add a new force list. The routine checks for duplicate itypes
506 * and will not add a second block of a certain type is one is
510 void addForces(const ListedForces
&forces
);
512 size_t nforces() const { return forces_
.size(); }
514 ListedForces
&lastForces() { return forces_
.back(); }
516 const ListedForces
&lastForces() const { return forces_
.back(); }
518 ListedForcesIterator
forcesBegin() { return forces_
.begin(); }
520 ListedForcesIterator
forcesEnd() { return forces_
.end(); }
522 ListedForcesConstIterator
forcesBegin() const { return forces_
.begin(); }
524 ListedForcesConstIterator
forcesEnd() const { return forces_
.end(); }
526 ListedForcesIterator
findForces(InteractionType iType
)
528 return std::find_if(forces_
.begin(), forces_
.end(),
529 [iType
](ListedForces
const &forces
)
530 { return (iType
== forces
.iType()); });
533 ListedForcesConstIterator
findForces(InteractionType iType
) const
535 return std::find_if(forces_
.begin(), forces_
.end(),
536 [iType
](ListedForces
const &forces
)
537 {return (iType
== forces
.iType()); });
540 bool findForce(std::vector
<std::string
> &atoms
,
541 ListedForceIterator
*force
);
544 bool findForce(const std::vector
<std::string
> &atoms
,
545 ListedForceConstIterator
*force
) const;
547 bool findForce(std::vector
<std::string
> &atoms
,
548 ListedForceIterator
*force
,
552 bool findForce(const std::vector
<std::string
> &atoms
,
553 ListedForceConstIterator
*force
,
554 size_t bondOrder
) const;
556 bool searchForce(std::vector
<std::string
> &atoms
,
560 size_t *ntrain
) const;
562 bool searchForceIType(std::vector
<std::string
> &atoms
,
567 InteractionType iType
) const;
569 bool searchForceBondOrder(std::vector
<std::string
> &atoms
,
574 size_t bondorder
) const;
576 bool searchForceBondOrderIType(std::vector
<std::string
> &atoms
,
582 InteractionType iType
) const;
584 const std::string
&getVdwFunction() const { return gtVdwFunction_
; }
586 const std::string
&getPolarUnit() const { return alexandriaPolarUnit_
; }
588 const std::string
&getPolarRef() const { return alexandriaPolarRef_
; }
590 const std::string
&getVsite_angle_unit() const { return vsite_angle_unit_
; }
592 const std::string
&getVsite_length_unit() const { return vsite_length_unit_
; }
594 void addSymcharges(const std::string
¢ral
,
595 const std::string
&attached
,
598 SymchargesIterator
getSymchargesBegin() { return symcharges_
.begin(); }
600 SymchargesIterator
getSymchargesEnd() { return symcharges_
.end(); }
602 SymchargesConstIterator
getSymchargesBegin() const { return symcharges_
.begin(); }
604 SymchargesConstIterator
getSymchargesEnd() const { return symcharges_
.end(); }
606 //! Return number of eemprops
607 size_t getNumprops() const { return eep_
.size();}
609 //! Return whether there is polarizability support for atype
610 int havePolSupport(const std::string
&atype
) const;
612 bool haveEemSupport(const std::string
&name
,
613 gmx_bool bAllowZeroParameters
) const;
615 double getJ00(const std::string
&name
) const;
617 int getNzeta(const std::string
&atype
) const;
619 double getZeta(const std::string
&name
, int zz
) const;
621 const char *getQstr(const std::string
&name
) const;
623 const char *getRowstr(const std::string
&name
) const;
625 double getQ(const std::string
&name
,
628 int getRow(const std::string
&name
,
631 double getChi0(const std::string
&name
) const;
633 const char *getOpts(const std::string
&name
) const;
635 void addEemprops(Eemprops eep
) { eep_
.push_back(eep
); }
637 EempropsConstIterator
BeginEemprops() const { return eep_
.begin(); }
639 EempropsConstIterator
EndEemprops() const { return eep_
.end(); }
641 EempropsIterator
BeginEemprops() { return eep_
.begin(); }
643 EempropsIterator
EndEemprops() { return eep_
.end(); }
645 /*! \brief Find the EEM properties
647 * Find the EEM properties corresponding to an atom type.
648 * \param[in] atype The Alexandria atom type
649 * \returns An iterator pointing to the right EEMprops
650 * structure or EndEemprops in case the atom type
653 EempropsConstIterator
atype2Eem(const std::string
&atype
) const
655 auto eic
= mapAtypeToEempropsConstIterator_
.find(atype
);
656 if (eic
!= mapAtypeToEempropsConstIterator_
.end())
662 return EndEemprops();
666 EempropsIterator
atype2Eem(const std::string
&atype
)
668 auto eic
= mapAtypeToEempropsIterator_
.find(atype
);
669 if (eic
!= mapAtypeToEempropsIterator_
.end())
675 return EndEemprops();
679 /*! \brief Find the EEM properties
681 * Find the EEM properties corresponding to a zeta type.
682 * \param[in] atype The Alexandria atom type
683 * \returns An iterator pointing to the right EEMprops
684 * structure or EndEemprops in case the atom type
687 EempropsConstIterator
ztype2Eem(const std::string
&ztype
) const
689 auto eic
= mapZtypeToEempropsConstIterator_
.find(ztype
);
690 if (eic
!= mapZtypeToEempropsConstIterator_
.end())
696 return EndEemprops();
700 EempropsIterator
ztype2Eem(const std::string
&ztype
)
702 auto eic
= mapZtypeToEempropsIterator_
.find(ztype
);
703 if (eic
!= mapZtypeToEempropsIterator_
.end())
709 return EndEemprops();
714 //! Return the charge distribution model used
715 ChargeModel
getChargeModel() const { return ChargeModel_
; }
717 //! Set the charge distribution model used
718 void setChargeModel(ChargeModel eqdModel
) { ChargeModel_
= eqdModel
; }
720 //! Set the charge distribution model used
721 void setChargeModel(const std::string eqdModel
)
723 ChargeModel_
= name2eemtype(eqdModel
);
726 //! Return the array of eemprops
727 std::vector
<Eemprops
> &getEemprops() {return eep_
; }
729 //! Set the reference for EEM property calculations
730 void setEpref(const std::string
&epref
) { eepReference_
= epref
; }
732 //! Get the reference for EEM property calculations
733 const std::string
&getEpref() const { return eepReference_
; }
735 //! Spread from master to slave nodes
736 void broadcast(const t_commrec
*cr
);
738 //! Spread eemprop from master to slave nodes
739 void broadcast_eemprop(const t_commrec
*cr
);
741 //! Spread ptype from master to slave nodes
742 void broadcast_ptype(const t_commrec
*cr
);
744 CommunicationStatus
Send(const t_commrec
*cr
, int dest
);
746 CommunicationStatus
Receive(const t_commrec
*cr
, int src
);
748 //! \brief Make tables using std::map to prevent searching
751 //! \brief Check internal consistency of data structures
752 void checkConsistency(FILE *fplog
) const;
754 std::string filename_
;
755 std::vector
<Ptype
> ptype_
;
756 std::vector
<Ffatype
> alexandria_
;
757 std::vector
<Vsite
> vsite_
;
758 std::vector
<std::string
> btype_
;
759 std::string alexandriaPolarUnit_
;
760 std::string alexandriaPolarRef_
;
761 std::string alexandriaVersion_
;
762 std::string vsite_angle_unit_
;
763 std::string vsite_length_unit_
;
765 std::string gtVdwFunction_
, gtCombinationRule_
;
766 int gtVdwFtype_
, gtCombRule_
;
767 double gtEpsilonR_
= 1.0;
768 std::vector
<ListedForces
> forces_
;
769 std::vector
<Miller
> miller_
;
770 std::string millerTauUnit_
, millerAhpUnit_
;
771 std::string millerRef_
;
772 std::vector
<Bosque
> bosque_
;
773 std::string bosquePolarUnit_
;
774 std::string bosqueRef_
;
775 std::vector
<Symcharges
> symcharges_
;
776 std::vector
<Eemprops
> eep_
;
777 std::string eepReference_
;
778 ChargeModel ChargeModel_
= eqdACM_g
;
780 void addBtype(const std::string
&btype
);
782 gmx_bool
strcasestrStart(std::string needle
, std::string haystack
);
785 int indexOfPointInVector(Type
* pointer
, std::vector
<Type
> vector
)
787 return (pointer
- &(vector
[0]));
790 std::map
<std::string
, EempropsConstIterator
> mapAtypeToEempropsConstIterator_
;
791 std::map
<std::string
, EempropsIterator
> mapAtypeToEempropsIterator_
;
792 std::map
<std::string
, EempropsConstIterator
> mapZtypeToEempropsConstIterator_
;
793 std::map
<std::string
, EempropsIterator
> mapZtypeToEempropsIterator_
;