Skip to content

Commit

Permalink
Merge branch 'master' into 561-layered-dihedrals
Browse files Browse the repository at this point in the history
  • Loading branch information
justinGilmer authored Oct 8, 2021
2 parents c6c3242 + 0f2ef1e commit 802185d
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 27 deletions.
8 changes: 6 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ stages:
- bash: |
source activate gmso-dev
bash <(curl -s https://codecov.io/bash) -C $(Build.SourceVersion)
condition: and( eq( variables['Agent.OS'], 'Linux' ), eq( variables['python.version'], '3.7' ) )
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -t ${CODECOV_UPLOAD_TOKEN} -C $(Build.SourceVersion)
condition: and( eq( variables['Agent.OS'], 'Linux' ), eq( variables['python.version'], '3.7' ) )
displayName: Upload coverage report to codecov.io
env:
CODECOV_UPLOAD_TOKEN: $(codecovUploadToken)
- task: PublishCodeCoverageResults@1
inputs:
Expand Down
34 changes: 34 additions & 0 deletions gmso/abc/abstract_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,40 @@ def connection_members(self):
def name(self):
return self.__dict__.get("name_")

@property
def member_types(self):
"""Return the atomtype of the connection members as a list of string."""
return self._get_members_types_or_classes("member_types_")

@property
def member_classes(self):
"""Return the class of the connection members as a list of string."""
return self._get_members_types_or_classes("member_classes_")

def _has_typed_members(self):
"""Check if all the members of this connection are typed."""
return all(
member.atom_type
for member in self.__dict__.get("connection_members_")
)

def _get_members_types_or_classes(self, to_return):
"""Return types or classes for connection members if they exist."""
assert to_return in {"member_types_", "member_classes_"}
ctype = getattr(self, "connection_type")
ctype_attr = getattr(ctype, to_return) if ctype else None

if ctype_attr:
return list(ctype_attr)
elif self._has_typed_members():
tc = [
member.atom_type.name
if to_return == "member_types_"
else member.atom_type.atomclass
for member in self.__dict__.get("connection_members_")
]
return tc if all(tc) else None

@root_validator(pre=True)
def validate_fields(cls, values):
connection_members = values.get("connection_members", [])
Expand Down
24 changes: 21 additions & 3 deletions gmso/core/angle_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ class AngleType(ParametricPotential):

member_types_: Optional[Tuple[str, str, str]] = Field(
None,
description="List-like of gmso.AtomType.name or gmso.AtomType.atomclass "
description="List-like of gmso.AtomType.name "
"defining the members of this angle type",
)

member_classes_: Optional[Tuple[str, str, str]] = Field(
None,
description="List-like of gmso.AtomType.atomclass "
"defining the members of this angle type",
)

Expand All @@ -38,6 +44,7 @@ def __init__(
independent_variables=None,
potential_expression=None,
member_types=None,
member_classes=None,
topology=None,
tags=None,
):
Expand All @@ -61,6 +68,7 @@ def __init__(
potential_expression=potential_expression,
topology=topology,
member_types=member_types,
member_classes=member_classes,
set_ref=ANGLE_TYPE_DICT,
tags=tags,
)
Expand All @@ -69,7 +77,17 @@ def __init__(
def member_types(self):
return self.__dict__.get("member_types_")

@property
def member_classes(self):
return self.__dict__.get("member_classes_")

class Config:
fields = {"member_types_": "member_types"}
fields = {
"member_types_": "member_types",
"member_classes_": "member_classes",
}

alias_to_fields = {"member_types": "member_types_"}
alias_to_fields = {
"member_types": "member_types_",
"member_classes": "member_classes_",
}
24 changes: 21 additions & 3 deletions gmso/core/bond_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ class BondType(ParametricPotential):

member_types_: Optional[Tuple[str, str]] = Field(
None,
description="List-like of of gmso.AtomType.name or gmso.AtomType.atomclass "
description="List-like of of gmso.AtomType.name "
"defining the members of this bond type",
)

member_classes_: Optional[Tuple[str, str]] = Field(
None,
description="List-like of of gmso.AtomType.atomclass "
"defining the members of this bond type",
)

Expand All @@ -39,6 +45,7 @@ def __init__(
independent_variables=None,
potential_expression=None,
member_types=None,
member_classes=None,
topology=None,
tags=None,
):
Expand All @@ -62,6 +69,7 @@ def __init__(
potential_expression=potential_expression,
topology=topology,
member_types=member_types,
member_classes=member_classes,
set_ref=BOND_TYPE_DICT,
tags=tags,
)
Expand All @@ -71,9 +79,19 @@ def member_types(self):
"""Return the members involved in this bondtype."""
return self.__dict__.get("member_types_")

@property
def member_classes(self):
return self.__dict__.get("member_classes_")

class Config:
"""Pydantic configuration for class attributes."""

fields = {"member_types_": "member_types"}
fields = {
"member_types_": "member_types",
"member_classes_": "member_classes",
}

alias_to_fields = {"member_types": "member_types_"}
alias_to_fields = {
"member_types": "member_types_",
"member_classes": "member_classes_",
}
26 changes: 22 additions & 4 deletions gmso/core/dihedral_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ class DihedralType(ParametricPotential):

member_types_: Optional[Tuple[str, str, str, str]] = Field(
None,
description="List-like of of gmso.AtomType.name or gmso.AtomType.atomclass "
description="List-like of of gmso.AtomType.name "
"defining the members of this dihedral type",
)

member_classes_: Optional[Tuple[str, str, str, str]] = Field(
None,
description="List-like of of gmso.AtomType.atomclass defining the "
"members of this dihedral type",
)

def __init__(
self,
name="DihedralType",
Expand All @@ -44,6 +50,7 @@ def __init__(
independent_variables=None,
potential_expression=None,
member_types=None,
member_classes=None,
topology=None,
tags=None,
):
Expand All @@ -68,6 +75,7 @@ def __init__(
potential_expression=potential_expression,
topology=topology,
member_types=member_types,
member_classes=member_classes,
set_ref=DIHEDRAL_TYPE_DICT,
tags=tags,
)
Expand All @@ -76,7 +84,17 @@ def __init__(
def member_types(self):
return self.__dict__.get("member_types_")

class Config:
fields = {"member_types_": "member_types"}
@property
def member_classes(self):
return self.__dict__.get("member_classes_")

alias_to_fields = {"member_types": "member_types_"}
class Config:
fields = {
"member_types_": "member_types",
"member_classes_": "member_classes",
}

alias_to_fields = {
"member_types": "member_types_",
"member_classes": "member_classes_",
}
24 changes: 21 additions & 3 deletions gmso/core/improper_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ class ImproperType(ParametricPotential):

member_types_: Optional[Tuple[str, str, str, str]] = Field(
None,
description="List-like of of gmso.AtomType.name or gmso.AtomType.atomclass "
description="List-like of gmso.AtomType.name "
"defining the members of this improper type",
)

member_classes_: Optional[Tuple[str, str, str, str]] = Field(
None,
description="List-like of gmso.AtomType.atomclass "
"defining the members of this improper type",
)

Expand All @@ -50,6 +56,7 @@ def __init__(
independent_variables=None,
potential_expression=None,
member_types=None,
member_classes=None,
topology=None,
tags=None,
):
Expand All @@ -74,6 +81,7 @@ def __init__(
potential_expression=potential_expression,
topology=topology,
member_types=member_types,
member_classes=member_classes,
set_ref=IMPROPER_TYPE_DICT,
tags=tags,
)
Expand All @@ -83,9 +91,19 @@ def member_types(self):
"""Return member information for this ImproperType."""
return self.__dict__.get("member_types_")

@property
def member_classes(self):
return self.__dict__.get("member_classes_")

class Config:
"""Pydantic configuration for attributes."""

fields = {"member_types_": "member_types"}
fields = {
"member_types_": "member_types",
"member_classes_": "member_classes",
}

alias_to_fields = {"member_types": "member_types_"}
alias_to_fields = {
"member_types": "member_types_",
"member_classes": "member_classes_",
}
4 changes: 4 additions & 0 deletions gmso/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ class MissingAtomTypesError(ForceFieldParseError):
"""Error for missing AtomTypes when creating a ForceField from an XML file."""


class MixedClassAndTypesError(ForceFieldParseError):
"""Error for missing AtomTypes when creating a ForceField from an XML file."""


class MissingPotentialError(ForceFieldError):
"""Error for missing Potential when searching for Potentials in a ForceField."""
6 changes: 3 additions & 3 deletions gmso/tests/files/ff-example0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
<BondTypes expression="0.5 * k * (r-r_eq)**2">
<ParametersUnitDef parameter="r_eq" unit="nm"/>
<ParametersUnitDef parameter="k" unit="kJ/mol"/>
<BondType name="BondType1" class1='Ar' type2='Ar'>
<BondType name="BondType1" type1='Ar' type2='Ar'>
<Parameters>
<Parameter name='r_eq' value="10.0"/>
<Parameter name='k' value="10000"/>
</Parameters>
</BondType>
<BondType name="BondType2" type1='Xe' class2="Xe">
<BondType name="BondType2" type1='Xe' type2="Xe">
<Parameters>
<Parameter name='r_eq' value="10"/>
<Parameter name='k' value="20000"/>
Expand Down Expand Up @@ -65,7 +65,7 @@
<DihedralTypes expression="0.5 * z * (r-r_eq)**2">
<ParametersUnitDef parameter="r_eq" unit="nm"/>
<ParametersUnitDef parameter="z" unit="kJ/mol"/>
<DihedralType name="DihedralType1" class1='Ar' class2='Ar' type3="Ar" type4="Ar">
<DihedralType name="DihedralType1" class1='Ar' class2='Ar' class3="Ar" class4="Ar">
<Parameters>
<Parameter name='r_eq' value="10.0"/>
<Parameter name='z' value="100"/>
Expand Down
33 changes: 33 additions & 0 deletions gmso/tests/test_bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,36 @@ def test_equivalent_members_set(self):

assert tuple(bond_eq.connection_members) in bond.equivalent_members()
assert tuple(bond.connection_members) in bond_eq.equivalent_members()

def test_bond_member_classes_none(self, typed_ethane):
bonds = typed_ethane.bonds
assert bonds[0].member_classes is None

def test_bond_member_types(self, typed_ethane):
bonds = typed_ethane.bonds
assert set(bonds[0].member_types) == set(["opls_135", "opls_140"])

def test_bond_member_classes_from_connection_members(self):
atype1 = AtomType(atomclass="CT", name="t1")

atype2 = AtomType(atomclass="CK", name="t2")

bond = Bond(
connection_members=[Atom(atom_type=atype1), Atom(atom_type=atype2)]
)
assert set(bond.member_classes) == set(["CT", "CK"])
assert set(bond.member_types) == set(["t1", "t2"])

def test_bond_member_types_classes_from_bond_type(self):
atom_type = AtomType()
atom1 = Atom(atom_type=atom_type)
atom2 = Atom(atom_type=atom_type)

btype = BondType(
name="atom1-atom2-bond",
member_types=["at1", "at2"],
member_classes=["XE", "XE"],
)
bond = Bond(connection_members=[atom1, atom2], bond_type=btype)
assert set(bond.member_classes) == set(["XE", "XE"])
assert set(bond.member_types) == set(["at1", "at2"])
6 changes: 3 additions & 3 deletions gmso/tests/test_forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_ff_angletypes_from_xml(self, ff):
assert ff.angle_types["Xe~Xe~Xe"].parameters["z"] == u.unyt_quantity(
20, u.kJ / u.mol
)
assert ff.angle_types["Xe~Xe~Xe"].member_types == ("Xe", "Xe", "Xe")
assert ff.angle_types["Xe~Xe~Xe"].member_classes == ("Xe", "Xe", "Xe")

def test_ff_dihedraltypes_from_xml(self, ff):
assert len(ff.dihedral_types) == 2
Expand All @@ -154,7 +154,7 @@ def test_ff_dihedraltypes_from_xml(self, ff):
assert ff.dihedral_types["Ar~Ar~Ar~Ar"].parameters[
"z"
] == u.unyt_quantity(100, u.kJ / u.mol)
assert ff.dihedral_types["Ar~Ar~Ar~Ar"].member_types == (
assert ff.dihedral_types["Ar~Ar~Ar~Ar"].member_classes == (
"Ar",
"Ar",
"Ar",
Expand All @@ -171,7 +171,7 @@ def test_ff_dihedraltypes_from_xml(self, ff):
assert ff.dihedral_types["Xe~Xe~Xe~Xe"].parameters[
"z"
] == u.unyt_quantity(20, u.kJ / u.mol)
assert ff.dihedral_types["Xe~Xe~Xe~Xe"].member_types == (
assert ff.dihedral_types["Xe~Xe~Xe~Xe"].member_classes == (
"Xe",
"Xe",
"Xe",
Expand Down
Loading

0 comments on commit 802185d

Please sign in to comment.