Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified RB and Periodic torsions #615

Open
wants to merge 19 commits into
base: old_main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions gmso/external/convert_foyer_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,9 @@ def _write_rb_torsions(forcefield, ff_kwargs):
forcefield,
"DihedralTypes",
attrib_dict={
"expression": "c0 * cos(phi)**0 + c1 * cos(phi)**1 + "
"c2 * cos(phi)**2 + c3 * cos(phi)**3 + "
"c4 * cos(phi)**4 + c5 * cos(phi)**5",
"expression": "c0 * cos(psi)**0 + c1 * cos(psi)**1 + "
"c2 * cos(psi)**2 + c3 * cos(psi)**3 + "
"c4 * cos(psi)**4 + c5 * cos(psi)**5",
},
)

Expand Down
2 changes: 1 addition & 1 deletion gmso/lib/jsons/PeriodicTorsionPotential.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "PeriodicTorsionPotential",
"expression": "k * (1 + cos(n * phi - phi_eq))",
"expression": "k0 + k1 * (1 + cos(1 * phi - phi_eq1)) + k2 * (1 + cos(2 * phi - phi_eq2)) + k3 * (1 + cos(3 * phi - phi_eq3)) + k4 * (1 + cos(4 * phi - phi_eq4)) + k5 * (1 + cos(5 * phi - phi_eq5))",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After spending some more thought on this, we might want to be careful with this eqn, especially regarding how many terms we want to support. As in, can we keep the old untouched and create a different/derivative for 5 terms, 4 terms, etc. More ideas/thoughts are welcome

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I hear what you mean. I think, If you do not supported fixed terms it may be harder to parse when you don’t know what is there for the engines. I believe We should be consistent, meaning if RB and OPLS is fixed this should be too.

Copy link
Contributor Author

@bc118 bc118 Dec 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don’t believe I saw anything ever past n=5 or power=5, which are both there converting to one or the other. The fixed term way in my mind is consistent for programming and the readers. I will make the general solution working in GOMC so it is the same as others.

I’m for the fixed one to the 5th power since all other ones RB and OPLS are fixed too. , but open if there is a specific reason not to do it that way.

Interested to hear what other think.

Though, many derivatives means that the FFs won’t be directly shareable. Whatever we pick we should stick to it as a general solution and not make derivative of it, or it will be hard or impossible to share FFs without manually rewriting or fixing to some extent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After additional though, if we decide to use the original periodic form, we should have additional check for the input variables. For example:

  • The valuables must me k1, … kx, n1, …, nx or phi1, …, phix. This will ensure the FFs are shareable.

  • k1 and phi1 must have n1=1 . Kx and phix must have nx =x

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this PR ready to close then, based on this comment thread?

"independent_variables": "phi"
}
4 changes: 2 additions & 2 deletions gmso/lib/jsons/RyckaertBellemansTorsionPotential.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "RyckaertBellemansTorsionPotential",
"expression": "c0 * cos(phi)**0 + c1 * cos(phi)**1 + c2 * cos(phi)**2 + c3 * cos(phi)**3 + c4 * cos(phi)**4 + c5 * cos(phi)**5",
"independent_variables": "phi"
"expression": "c0 + c1 * cos(psi)**1 + c2 * cos(psi)**2 + c3 * cos(psi)**3 + c4 * cos(psi)**4 + c5 * cos(psi)**5",
"independent_variables": "psi"
}
42 changes: 29 additions & 13 deletions gmso/tests/files/carbon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,48 @@
<BondTypes expression="0.5 * k * (r-r_eq)**2">
<ParametersUnitDef parameter="r_eq" unit="nm"/>
<ParametersUnitDef parameter="k" unit="kJ/(mol*nm**2)"/>
<BondType name="BondType1" type1='C' type2='C'>
<BondType name="BondType1" type1="C" type2="C">
<Parameters>
<Parameter name='r_eq' value="0.1324"/>
<Parameter name='k' value="493460.96"/>
<Parameter name="r_eq" value="0.1324"/>
<Parameter name="k"value="493460.96"/>
</Parameters>
</BondType>
</BondTypes>
<AngleTypes expression="0.5 * k * (theta-theta_eq)**2">
<ParametersUnitDef parameter="theta_eq" unit="radian"/>
<ParametersUnitDef parameter="k" unit="kJ/(mol*radian**2)"/>
<AngleType name="AngleType1" type1='C' type2='C' type3="C">
<AngleType name="AngleType1" type1="'C" type2="'C'" type3="C">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<AngleType name="AngleType1" type1="'C" type2="'C'" type3="C">
<AngleType name="AngleType1" type1="C" type2="C" type3="C">

<Parameters>
<Parameter name='theta_eq' value="2.12598556185"/>
<Parameter name='k' value="584.42112"/>
<Parameter name="theta_eq" value="2.12598556185"/>
<Parameter name="k" value="584.42112"/>
</Parameters>
</AngleType>
</AngleTypes>
<DihedralTypes expression="k * (1 + cos(n * theta - theta_0))">
<ParametersUnitDef parameter="k" unit="kJ/mol"/>
<ParametersUnitDef parameter="n" unit="dimensionless"/>
<ParametersUnitDef parameter="theta_0" unit="radian"/>
<DihedralTypes expression="k0 + k1 * (1 + cos(1 * phi - phi_eq1)) + k2 * (1 + cos(2 * phi - phi_eq2)) + k3 * (1 + cos(3 * phi - phi_eq3)) + k4 * (1 + cos(4 * phi - phi_eq4)) + k5 * (1 + cos(5 * phi - phi_eq5))"">
<ParametersUnitDef parameter="k0" unit="kJ/mol"/>
<ParametersUnitDef parameter="k1" unit="kJ/mol"/>
<ParametersUnitDef parameter="phi_eq1" unit="radian"/>
<ParametersUnitDef parameter="k2" unit="kJ/mol"/>
<ParametersUnitDef parameter="phi_eq2" unit="radian"/>
<ParametersUnitDef parameter="k3" unit="kJ/mol"/>
<ParametersUnitDef parameter="phi_eq3" unit="radian"/>
<ParametersUnitDef parameter="k4" unit="kJ/mol"/>
<ParametersUnitDef parameter="phi_eq4" unit="radian"/>
<ParametersUnitDef parameter="k5" unit="kJ/mol"/>
<ParametersUnitDef parameter="phi_eq5" unit="radian"/>
<DihedralType name="DihedralType1" type1="" type2="C" type3="C" type4="">
<Parameters>
<Parameter name='k' value="27.8236"/>
<Parameter name='n' value="2"/>
<Parameter name='theta_0' value="3.14159265359"/>
<Parameter name="k0" value="0"/>
<Parameter name="k1" value="0"/>
<Parameter name="phi_eq1" value="0"/>
<Parameter name="k2" value="27.8236"/>
<Parameter name="phi_eq2" value="3.14159265359"/>
<Parameter name="k3" value="0"/>
<Parameter name="phi_eq3" value="0"/>
<Parameter name="k4" value="0"/>
<Parameter name="phi_eq4" value="0"/>
<Parameter name="k5" value="0"/>
<Parameter name="phi_eq5" value="0"/>
</Parameters>
</DihedralType>
</DihedralTypes>
Expand Down
26 changes: 13 additions & 13 deletions gmso/tests/files/ethylene.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@
</Parameters>
</AngleType>
</AngleTypes>
<DihedralTypes expression="c_0 + c_1 * cos(psi) + c_2 * cos(psi)**2 + c_3 * cos(psi)**3 + c_4 * cos(psi)**4 + c_5 * cos(psi)**5">
<ParametersUnitDef parameter="c_0" unit="kJ/mol"/>
<ParametersUnitDef parameter="c_1" unit="kJ/mol"/>
<ParametersUnitDef parameter="c_2" unit="kJ/mol"/>
<ParametersUnitDef parameter="c_3" unit="kJ/mol"/>
<ParametersUnitDef parameter="c_4" unit="kJ/mol"/>
<ParametersUnitDef parameter="c_5" unit="kJ/mol"/>
<DihedralTypes expression="c0 + c1 * cos(psi) + c2 * cos(psi)**2 + c3 * cos(psi)**3 + c4 * cos(psi)**4 + c5 * cos(psi)**5">
<ParametersUnitDef parameter="c0" unit="kJ/mol"/>
<ParametersUnitDef parameter="c1" unit="kJ/mol"/>
<ParametersUnitDef parameter="c2" unit="kJ/mol"/>
<ParametersUnitDef parameter="c3" unit="kJ/mol"/>
<ParametersUnitDef parameter="c4" unit="kJ/mol"/>
<ParametersUnitDef parameter="c5" unit="kJ/mol"/>
<DihedralType name="DihedralType-RyckaertBellemans-1" type1="opls_144" type2="opls_143" type3="opls_143" type4="opls_144">
<Parameters>
<Parameter name="c_0" value="58.576"/>
<Parameter name="c_1" value="0.0"/>
<Parameter name="c_2" value="-58.576"/>
<Parameter name="c_3" value="0.0"/>
<Parameter name="c_4" value="0.0"/>
<Parameter name="c_5" value="0.0"/>
<Parameter name="c0" value="58.576"/>
<Parameter name="c1" value="0.0"/>
<Parameter name="c2" value="-58.576"/>
<Parameter name="c3" value="0.0"/>
<Parameter name="c4" value="0.0"/>
<Parameter name="c5" value="0.0"/>
</Parameters>
</DihedralType>
</DihedralTypes>
Expand Down
2 changes: 1 addition & 1 deletion gmso/tests/files/ff-example1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
</ImproperType>
</DihedralTypes>

<DihedralTypes name="RBProper" expression="c0 * cos(phi)**0 + c1 * cos(phi)**1 + c2 * cos(phi)**2 + c3 * cos(phi)**3 + c4 * cos(phi)**4 + c5 * cos(phi)**5">
<DihedralTypes name="RBProper" expression="c0 + c1 * cos(psi)**1 + c2 * cos(psi)**2 + c3 * cos(psi)**3 + c4 * cos(psi)**4 + c5 * cos(psi)**5">
<ParametersUnitDef parameter="c5" unit="kJ/mol"/>
<ParametersUnitDef parameter="c4" unit="kJ/mol"/>
<ParametersUnitDef parameter="c3" unit="kJ/mol"/>
Expand Down
44 changes: 22 additions & 22 deletions gmso/tests/files/ff_missing_atom_types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,66 +31,66 @@
<BondTypes name="HarmonicBond" expression="0.5 * k * (r-r_eq)**2">
<ParametersUnitDef parameter="r_eq" unit="nm"/>
<ParametersUnitDef parameter="k" unit="kJ/mol"/>
<BondType name="BondType1" type1='Ar' type2='Ar'>
<BondType name="BondType1" type1="Ar" type2="Ar"'>
<Parameters>
<Parameter name='r_eq' value="10.0"/>
<Parameter name='k' value="10000"/>
<Parameter name="r_eq" value="10.0"/>
<Parameter name="'k" value="10000"/>
</Parameters>
</BondType>
<BondType name="BondType2" type1='Xe' type2="Xe">
<BondType name="BondType2" type1="Xe" type2="Xe">
<Parameters>
<Parameter name='r_eq' value="10"/>
<Parameter name='k' value="20000"/>
<Parameter name="'r_eq"' value="10"/>
<Parameter name="'k'" value="20000"/>
</Parameters>
</BondType>
</BondTypes>

<AngleTypes name="HarmonicAngle" expression="0.5 * z * (r-r_eq)**2">
<ParametersUnitDef parameter="r_eq" unit="nm"/>
<ParametersUnitDef parameter="z" unit="kJ/mol"/>
<AngleType name="AngleType1" type1='Ar' type2='Ar' type3="Ar">
<AngleType name="AngleType1" type1="'Ar" type2="Ar" type3="Ar">
<Parameters>
<Parameter name='r_eq' value="10.0"/>
<Parameter name='z' value="100"/>
<Parameter name="r_eq" value="10.0"/>
<Parameter name="z'" value="100"/>
</Parameters>
</AngleType>
<AngleType name="AngleType2" type1='Xe' type2="Xe" type3="Xe">
<AngleType name="AngleType2" type1="Xe" type2="Xe" type3="Xe">
<Parameters>
<Parameter name='r_eq' value="10"/>
<Parameter name='z' value="20"/>
<Parameter name="'r_eq" value="10"/>
<Parameter name="'z"' value="20"/>
</Parameters>
</AngleType>
</AngleTypes>

<DihedralTypes name="PeriodicProper" expression="0.5 * z * (r-r_eq)**2">
<ParametersUnitDef parameter="r_eq" unit="nm"/>
<ParametersUnitDef parameter="z" unit="kJ/mol"/>
<DihedralType name="ProperType1" type1='Ar' type2='Ar' type3="Ar" type4="Ar">
<DihedralType name="ProperType1" type1="Ar" type2="Ar" type3="Ar" type4="Ar">
<Parameters>
<Parameter name='r_eq' value="10.0"/>
<Parameter name='z' value="100"/>
<Parameter name="'r_eq" value="10.0"/>
<Parameter name="'z" value="100"/>
</Parameters>
</DihedralType>
<DihedralType name="ProperType2" type1='Xe' type2="Xe" type3="Xe" type4="Xe">
<DihedralType name="ProperType2" type1="Xe" type2="Xe" type3="Xe" type4="Xe">
<Parameters>
<Parameter name='r_eq' value="10"/>
<Parameter name='z' value="20"/>
<Parameter name="r_eq" value="10"/>
<Parameter name="z" value="20"/>
</Parameters>
</DihedralType>
</DihedralTypes>

<DihedralTypes name="PeriodicImproper" expression="0.5 * z * (r-r_eq)**2">
<ParametersUnitDef parameter="r_eq" unit="nm"/>
<ParametersUnitDef parameter="z" unit="kJ/mol"/>
<ImproperType name="ImproperType1" type1='Ar' type2='Ar' type3="Ar" type4="Ar">
<ImproperType name="ImproperType1" type1="Ar" type2="A" type3="Ar" type4="Ar">
<Parameters>
<Parameter name='r_eq' value="10.0"/>
<Parameter name='z' value="100"/>
<Parameter name="r_eq" value="10.0"/>
<Parameter name="z" value="100"/>
</Parameters>
</ImproperType>
</DihedralTypes>

<DihedralTypes name="RBProper" expression="c0 * cos(phi)**0 + c1 * cos(phi)**1 + c2 * cos(phi)**2 + c3 * cos(phi)**3 + c4 * cos(phi)**4 + c5 * cos(phi)**5">
<DihedralTypes name="RBProper" expression="c0 + c1 * cos(psi)**1 + c2 * cos(psi)**2 + c3 * cos(psi)**3 + c4 * cos(psi)**4 + c5 * cos(psi)**5">
<ParametersUnitDef parameter="c5" unit="kJ/mol"/>
<ParametersUnitDef parameter="c4" unit="kJ/mol"/>
<ParametersUnitDef parameter="c3" unit="kJ/mol"/>
Expand Down
2 changes: 1 addition & 1 deletion gmso/tests/files/oplsaa-ethane_foyer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</Parameters>
</AngleType>
</AngleTypes>
<DihedralTypes expression="c0 * cos(phi)**0 + c1 * cos(phi)**1 + c2 * cos(phi)**2 + c3 * cos(phi)**3 + c4 * cos(phi)**4 + c5 * cos(phi)**5">
<DihedralTypes expression="c0 + c1 * cos(psi)**1 + c2 * cos(psi)**2 + c3 * cos(psi)**3 + c4 * cos(psi)**4 + c5 * cos(psi)**5">
<ParametersUnitDef parameter="c5" unit="kJ/mol"/>
<ParametersUnitDef parameter="c4" unit="kJ/mol"/>
<ParametersUnitDef parameter="c3" unit="kJ/mol"/>
Expand Down
8 changes: 4 additions & 4 deletions gmso/tests/test_internal_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_invalid_connection_type(self, templates):

name = ryckaert_bellemans_torsion_potential.name
expression = (
str(ryckaert_bellemans_torsion_potential.expression) + " + 3 * psi"
str(ryckaert_bellemans_torsion_potential.expression) + " + 3 * phi"
)
variables = ["phi", "psi"]

Expand All @@ -49,7 +49,7 @@ def test_invalid_connection_type(self, templates):
ryckaert_connection_type
)

expression = "c0+c1+c2+c3+c4+c5+phi"
expression = "c0+c1+c2+c3+c4+c5+psi"
variables = ryckaert_bellemans_torsion_potential.independent_variables
ryckaert_connection_type = DihedralType(
name=name,
Expand Down Expand Up @@ -149,7 +149,7 @@ def test_ryckaert_to_opls(self, templates):
(param, val)
for param, val in {
**ryckaert_connection_type.parameters,
"phi": angle - np.pi,
"psi": angle - np.pi,
}.items()
]
)
Expand Down Expand Up @@ -206,7 +206,7 @@ def test_opls_to_ryckaert(self, templates):
(param, val)
for param, val in {
**ryckaert_connection_type.parameters,
"phi": angle - np.pi,
"psi": angle - np.pi,
}.items()
]
)
Expand Down
18 changes: 12 additions & 6 deletions gmso/tests/test_potential_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def test_opls_torsion_potential(self, templates):
opls_torsion_potential = templates["OPLSTorsionPotential"]
assert opls_torsion_potential.name == "OPLSTorsionPotential"
assert opls_torsion_potential.expression == sympy.sympify(
"0.5 * k0 + 0.5 * k1 * (1 + cos(phi)) +"
"0.5 * k0 + "
"0.5 * k1 * (1 + cos(phi)) +"
"0.5 * k2 * (1 - cos(2*phi)) +"
"0.5 * k3 * (1 + cos(3*phi)) +"
"0.5 * k4 * (1 - cos(4*phi))"
Expand All @@ -52,7 +53,12 @@ def test_periodic_torsion_potential(self, templates):
periodic_torsion_potential = templates["PeriodicTorsionPotential"]
assert periodic_torsion_potential.name == "PeriodicTorsionPotential"
assert periodic_torsion_potential.expression == sympy.sympify(
"k * (1 + cos(n * phi - phi_eq))"
"k0 + "
"k1 * (1 + cos(1 * phi - phi_eq1)) + "
"k2 * (1 + cos(2 * phi - phi_eq2)) + "
"k3 * (1 + cos(3 * phi - phi_eq3)) + "
"k4 * (1 + cos(4 * phi - phi_eq4)) + "
"k5 * (1 + cos(5 * phi - phi_eq5))"
)
assert periodic_torsion_potential.independent_variables == {
sympy.sympify("phi")
Expand All @@ -67,12 +73,12 @@ def test_ryckaert_bellemans_torsion_potential(self, templates):
== "RyckaertBellemansTorsionPotential"
)
assert ryckaert_bellemans_torsion_potential.expression == sympy.sympify(
"c0 * cos(phi)**0 + c1 * cos(phi)**1 +"
" c2 * cos(phi)**2 + c3 * cos(phi)**3 +"
" c4 * cos(phi)**4 + c5 * cos(phi)**5"
"c0 + c1 * cos(psi)**1 +"
" c2 * cos(psi)**2 + c3 * cos(psi)**3 +"
" c4 * cos(psi)**4 + c5 * cos(psi)**5"
)
assert ryckaert_bellemans_torsion_potential.independent_variables == {
sympy.sympify("phi")
sympy.sympify("psi")
}

def test_harmonic_torsion_potential(self, templates):
Expand Down
14 changes: 11 additions & 3 deletions gmso/tests/test_top.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,17 @@ def test_ethane_periodic(self, typed_ethane):

per_torsion = PotentialTemplateLibrary()["PeriodicTorsionPotential"]
params = {
"k": 10 * u.Unit("kJ / mol"),
"phi_eq": 15 * u.Unit("degree"),
"n": 3 * u.Unit("dimensionless"),
"k0": 10 * u.Unit("kJ / mol"),
"k1": 1 * u.Unit("kJ / mol"),
"phi_eq1": 180 * u.Unit("degree"),
"k2": 2 * u.Unit("kJ / mol"),
"phi_eq2": 0 * u.Unit("degree"),
"k3": 3 * u.Unit("kJ / mol"),
"phi_eq3": 180 * u.Unit("degree"),
"k4": 4 * u.Unit("kJ / mol"),
"phi_eq4": 0 * u.Unit("degree"),
"k5": 5 * u.Unit("kJ / mol"),
"phi_eq5": 180 * u.Unit("degree"),
}
periodic_dihedral_type = ParametricPotential.from_template(
potential_template=per_torsion, parameters=params
Expand Down