Skip to content

Commit

Permalink
Possible fix to finish openmm#191
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwthompson committed Aug 9, 2022
1 parent bdf5ebb commit 0478946
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion openmmforcefields/generators/template_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,8 @@ def convert_system_to_ffxml(self, molecule, system, improper_atom_ordering='smir
ffxml_contents : str
The OpenMM ffxml contents for the given molecule.
"""
# OpenFF Toolkit v0.11.0 removed Atom.element and replced it with Atom.symbol, etc.
uses_old_api = hasattr(molecule.atoms[0], "element")

# Generate OpenMM ffxml definition for this molecule
from lxml import etree
Expand All @@ -962,8 +964,9 @@ def as_attrib(quantity):
for particle_index, particle in enumerate(molecule.particles):
# Create a new atom type for each atom in the molecule
paricle_indices = [particle_index]
element_symbol = particle.element.symbol if uses_old_api else particle.symbol
atom_type = etree.SubElement(atom_types, "Type", name=particle.typename,
element=particle.element.symbol, mass=as_attrib(particle.element.mass))
element=element_symbol, mass=as_attrib(particle.element.mass))
atom_type.set('class', particle.typename) # 'class' is a reserved Python keyword, so use alternative API

# Compile forces into a dict
Expand Down

0 comments on commit 0478946

Please sign in to comment.