Skip to content

Commit

Permalink
revised load_xyz function (#1140)
Browse files Browse the repository at this point in the history
* revised load_xyz function

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Co Quach <43968221+daico007@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 5, 2023
1 parent b4836ae commit c5872e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion mbuild/formats/xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def read_xyz(filename, compound=None):

guessed_elements = set()

compound_list = []
with open(filename, "r") as xyz_file:
n_atoms = int(xyz_file.readline())
xyz_file.readline()
Expand Down Expand Up @@ -74,7 +75,7 @@ def read_xyz(filename, compound=None):
element = None

particle = mb.Compound(pos=coords[row], name=name, element=element)
compound.add(particle)
compound_list.append(particle)

# Verify we have read the last line by ensuring the next line in blank
line = xyz_file.readline().split()
Expand All @@ -86,6 +87,8 @@ def read_xyz(filename, compound=None):
)
raise MBuildError(msg.format(n_atoms))

compound.add(compound_list)

return compound


Expand Down
5 changes: 4 additions & 1 deletion mbuild/packing.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,9 +888,12 @@ def _create_topology(container, comp_to_add, n_compounds):
container : mb.Compound
Compound with added compounds from PACKMOL.
"""
container_list = []
for comp, m_compound in zip(comp_to_add, n_compounds):
for _ in range(m_compound):
container.add(clone(comp))
container_list.append(clone(comp))

container.add(container_list)
return container


Expand Down

0 comments on commit c5872e7

Please sign in to comment.