Skip to content

Commit

Permalink
Merge pull request #51 from openforcefield/str-slots
Browse files Browse the repository at this point in the history
Store "slot" identifiers as str
  • Loading branch information
mattwthompson authored Nov 17, 2020
2 parents 586509c + 839d215 commit b751351
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/smirnoff_argon.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"# SMIRKS pattern as a key connecting the topological data to the\n",
"# parametrized data\n",
"sys_out.handlers['vdW'].potentials[\n",
" sys_out.handlers['vdW'].slot_map[(0,)]\n",
" sys_out.handlers['vdW'].slot_map[\"(0,)\"]\n",
"].parameters['sigma']"
]
}
Expand Down
2 changes: 1 addition & 1 deletion examples/smirnoff_ethanol.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"# SMIRKS pattern as a key connecting the topological data to the\n",
"# parametrized data\n",
"sys_out.handlers['Bonds'].potentials[\n",
" sys_out.handlers['Bonds'].slot_map[(1, 7)]\n",
" sys_out.handlers['Bonds'].slot_map[\"(1, 7)\"]\n",
"].parameters['k']"
]
}
Expand Down
2 changes: 1 addition & 1 deletion openff/system/components/potentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PotentialHandler(BaseModel):
name: str
expression: Union[Expr, str]
independent_variables: Union[str, Set[Union[Expr, str]]]
slot_map: Dict[tuple, str] = dict()
slot_map: Dict[str, str] = dict()
potentials: Dict[str, Potential] = dict()

@validator("expression")
Expand Down
12 changes: 8 additions & 4 deletions openff/system/components/smirnoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SMIRNOFFBondHandler(PotentialHandler):
name: str = "Bonds"
expression: str = "1/2 * k * (r - length) ** 2"
independent_variables: Set[str] = {"r"}
slot_map: Dict[tuple, str] = dict()
slot_map: Dict[str, str] = dict()
potentials: Dict[str, Potential] = dict()

def store_matches(self, parameter_handler: BondHandler, topology: Topology) -> None:
Expand All @@ -33,6 +33,7 @@ def store_matches(self, parameter_handler: BondHandler, topology: Topology) -> N
self.slot_map = dict()
matches = parameter_handler.find_matches(topology)
for key, val in matches.items():
key = str(key)
self.slot_map[key] = val.parameter_type.smirks

def store_potentials(self, parameter_handler: BondHandler) -> None:
Expand All @@ -59,7 +60,7 @@ class SMIRNOFFAngleHandler(PotentialHandler):
name: str = "Angles"
expression: str = "1/2 * k * (angle - theta)"
independent_variables: Set[str] = {"theta"}
slot_map: Dict[tuple, str] = dict()
slot_map: Dict[str, str] = dict()
potentials: Dict[str, Potential] = dict()

def store_matches(
Expand All @@ -72,6 +73,7 @@ def store_matches(
"""
matches = parameter_handler.find_matches(topology)
for key, val in matches.items():
key = str(key)
self.slot_map[key] = val.parameter_type.smirks

def store_potentials(self, parameter_handler: AngleHandler) -> None:
Expand All @@ -98,7 +100,7 @@ class SMIRNOFFProperTorsionHandler(PotentialHandler):
name: str = "ProperTorsions"
expression: str = "k*(1+cos(periodicity*theta-phase))"
independent_variables: Set[str] = {"theta"}
slot_map: Dict[tuple, str] = dict()
slot_map: Dict[str, str] = dict()
potentials: Dict[str, Potential] = dict()

def store_matches(
Expand All @@ -111,6 +113,7 @@ def store_matches(
"""
matches = parameter_handler.find_matches(topology)
for key, val in matches.items():
key = str(key)
self.slot_map[key] = val.parameter_type.smirks

def store_potentials(self, parameter_handler: ProperTorsionHandler) -> None:
Expand Down Expand Up @@ -138,7 +141,7 @@ class SMIRNOFFvdWHandler(PotentialHandler):
name: str = "vdW"
expression: str = "4*epsilon*((sigma/r)**12-(sigma/r)**6)"
independent_variables: Set[str] = {"r"}
slot_map: Dict[tuple, str] = dict()
slot_map: Dict[str, str] = dict()
potentials: Dict[str, Potential] = dict()

def store_matches(
Expand All @@ -153,6 +156,7 @@ def store_matches(
"""
matches = parameter_handler.find_matches(topology)
for key, val in matches.items():
key = str(key)
self.slot_map[key] = val.parameter_type.smirks

def store_potentials(self, parameter_handler: vdWHandler) -> None:
Expand Down
4 changes: 2 additions & 2 deletions openff/system/tests/test_potential.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_bond_parameter_handler(self):
forcefield.register_parameter_handler(bond_handler)
bond_potentials = forcefield["Bonds"].create_potential(top)

pot = bond_potentials.potentials[bond_potentials.slot_map[(0, 1)]]
pot = bond_potentials.potentials[bond_potentials.slot_map["(0, 1)"]]
kcal_ang2_mol = omm_unit.kilocalorie_per_mole / omm_unit.angstrom ** 2

assert pot.parameters["k"] == simtk_to_pint(1.5 * kcal_ang2_mol)
Expand All @@ -48,7 +48,7 @@ def test_angle_parameter_handler(self):
forcefield.register_parameter_handler(angle_handler)
angle_potentials = forcefield["Angles"].create_potential(top)

pot = angle_potentials.potentials[angle_potentials.slot_map[(0, 1, 2)]]
pot = angle_potentials.potentials[angle_potentials.slot_map["(0, 1, 2)"]]
kcal_deg2_mol = omm_unit.kilocalorie_per_mole / omm_unit.degree ** 2

assert pot.parameters["k"] == simtk_to_pint(2.5 * kcal_deg2_mol)

0 comments on commit b751351

Please sign in to comment.