Skip to content

Commit

Permalink
parse charge and mass in convert mbuild (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
daico007 committed Aug 16, 2022
1 parent d7ddc5b commit 5912c64
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions gmso/external/convert_mbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,17 @@ def from_mbuild_box(mb_box):
def _parse_particle(particle_map, site):
"""Parse information for a mb.Particle from a gmso.Site and add it to particle map."""
element = site.element.symbol if site.element else None
charge = (
site.charge.in_units(u.elementary_charge).value if site.charge else None
)
mass = site.mass.in_units(u.amu).value if site.mass else None

particle = mb.Compound(
name=site.name,
pos=site.position.to_value(u.nm),
element=element,
charge=charge,
mass=mass,
)
particle_map[site] = particle
return particle
Expand All @@ -234,14 +240,20 @@ def _parse_particle(particle_map, site):
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."""
pos = particle.xyz[0] * u.nm
if particle.element:
ele = search_method(particle.element.symbol)
else:
ele = search_method(particle.name)
ele = (
search_method(particle.element.symbol)
if particle.element
else search_method(particle.name)
)
charge = particle.charge * u.elementary_charge if particle.charge else None
mass = particle.mass * u.amu if particle.mass else None

site = Atom(
name=particle.name,
position=pos,
element=ele,
charge=charge,
mass=mass,
molecule=site_map[particle]["molecule"],
residue=site_map[particle]["residue"],
)
Expand Down

0 comments on commit 5912c64

Please sign in to comment.