Skip to content

Commit

Permalink
Merge branch 'main' into 700-lammpswrite-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
daico007 committed Feb 2, 2023
2 parents b2862cc + fae7918 commit 7c2a488
Show file tree
Hide file tree
Showing 37 changed files with 3,091 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ repos:
- id: black
args: [--line-length=80]
- repo: https://github.com/pycqa/isort
rev: 5.11.1
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
args: [--profile=black, --line-length=80]
- repo: https://github.com/pycqa/pydocstyle
rev: '6.1.1'
rev: '6.3.0'
hooks:
- id: pydocstyle
exclude: ^(gmso/abc|gmso/core|gmso/tests/|docs/|devtools/|setup.py)
Expand Down
2 changes: 1 addition & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies:
- python>=3.8
- numpy
- sympy
- unyt
- unyt<=2.9.2
- boltons
- lxml
- pydantic>1.8
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies:
- python>=3.8
- numpy
- sympy
- unyt
- unyt<=2.9.2
- boltons
- lxml
- pydantic>1.8
Expand Down
2 changes: 1 addition & 1 deletion gmso/core/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def _unit_vectors_from_angles(self):
# and then the xy plane, with the z-axis
box_vec = [[1, 0, 0], [cosg, sing, 0], [cosb, mat_coef_y, mat_coef_z]]

return u.unyt_array(box_vec, u.dimensionless, dtype=np.float)
return u.unyt_array(box_vec, u.dimensionless, dtype=float)

def get_vectors(self):
"""Return the vectors of the box."""
Expand Down
6 changes: 4 additions & 2 deletions gmso/core/forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,14 +613,16 @@ def _xml_from_gmso(self, filename, overwrite=False):
)

metadata = etree.SubElement(ff_el, "FFMetaData")
if not self.scaling_factors.get("electrostatics14Scale") is None:
if self.scaling_factors.get("electrostatics14Scale") is not None:
metadata.attrib["electrostatics14Scale"] = str(
self.scaling_factors.get("electrostatics14Scale")
)
if not self.scaling_factors.get("nonBonded14Scale") is None:
if self.scaling_factors.get("nonBonded14Scale") is not None:
metadata.attrib["nonBonded14Scale"] = str(
self.scaling_factors.get("nonBonded14Scale")
)
if self.combining_rule is not None:
metadata.attrib["combiningRule"] = str(self.combining_rule)

# ToDo: ParameterUnitsDefintions and DefaultUnits
if self.units:
Expand Down
18 changes: 14 additions & 4 deletions gmso/external/convert_mbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def from_mbuild(
search_method=element_by_symbol,
parse_label=True,
custom_groups=None,
infer_elements=False,
):
"""Convert an mbuild.Compound to a gmso.Topology.
Expand Down Expand Up @@ -75,6 +76,9 @@ def from_mbuild(
matching name on the way down from compound.children. Only the first match
while moving downwards will be assigned to the site. If parse_label=False,
this argument does nothing.
infer_elements : bool, default=False
Allows the reader to try to load element info from the mbuild Particle.name
instead of only from the populated Particle.element
Returns
-------
Expand Down Expand Up @@ -104,7 +108,9 @@ def from_mbuild(

# Use site map to apply Compound info to Topology.
for part in compound.particles():
site = _parse_site(site_map, part, search_method)
site = _parse_site(
site_map, part, search_method, infer_element=infer_elements
)
top.add_site(site)

for b1, b2 in compound.bonds():
Expand Down Expand Up @@ -247,10 +253,14 @@ def _parse_particle(particle_map, site):
return particle


def _parse_site(site_map, particle, search_method):
"""Parse information for a gmso.Site from a mBuild.Compound adn add it to the site map."""
def _parse_site(site_map, particle, search_method, infer_element=False):
"""Parse information for a gmso.Site from a mBuild.Compound and add it to the site map."""
pos = particle.xyz[0] * u.nm
ele = search_method(particle.element.symbol) if particle.element else None
if particle.element:
ele = search_method(particle.element.symbol)
else:
ele = search_method(particle.name) if infer_element else None

charge = particle.charge * u.elementary_charge if particle.charge else None
mass = particle.mass * u.amu if particle.mass else None

Expand Down
2 changes: 1 addition & 1 deletion gmso/formats/xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def read_xyz(filename):
"were expected, but at least one fewer was found."
)
raise ValueError(msg.format(n_atoms))
tmp = np.array(line[1:4], dtype=np.float) * u.angstrom
tmp = np.array(line[1:4], dtype=float) * u.angstrom
coords[row] = tmp.in_units(u.nanometer)
site = Atom(name=line[0], position=coords[row])
top.add_site(site)
Expand Down
3 changes: 1 addition & 2 deletions gmso/parameterization/foyer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_topology_graph(
if atomdata_populator
else {}
)
if atom.name.startswith("_"):
if atom.name.startswith("_") or not atom.element:
top_graph.add_atom(
name=atom.name,
index=j, # Assumes order is preserved
Expand All @@ -70,7 +70,6 @@ def get_topology_graph(
molecule=atom.molecule.name if atom.molecule else None,
**kwargs,
)

else:
top_graph.add_atom(
name=atom.name,
Expand Down
20 changes: 20 additions & 0 deletions gmso/tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,3 +649,23 @@ def hierarchical_top(self, hierarchical_compound):
top = from_mbuild(hierarchical_compound) # Create GMSO topology
top.identify_connections()
return top

@pytest.fixture
def ethane_gomc(self):
ethane_gomc = mb.load("CC", smiles=True)
ethane_gomc.name = "ETH"

return ethane_gomc

@pytest.fixture
def ethanol_gomc(self):
ethanol_gomc = mb.load("CCO", smiles=True)
ethanol_gomc.name = "ETO"

return ethanol_gomc

@pytest.fixture
def methane_ua_gomc(self):
methane_ua_gomc = mb.Compound(name="_CH4")

return methane_ua_gomc
Loading

0 comments on commit 7c2a488

Please sign in to comment.