Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve speedup of large lattice #1198

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions mbuild/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ def populate(self, compound_dict=None, x=1, y=1, z=1):
ret_lattice = mb.Compound()

# Create (clone) a mb.Compound for the newly generate positions
compoundsList = [] # particles to add at the end
elementsSet = set()
if compound_dict is None:
for key_id, all_pos in cell.items():
Expand All @@ -641,15 +642,15 @@ def populate(self, compound_dict=None, x=1, y=1, z=1):
for pos in all_pos:
particle_to_add = mb.clone(particle)
particle_to_add.translate_to(list(pos))
ret_lattice.add(particle_to_add)
compoundsList.append(particle_to_add)
else:
for key_id, all_pos in cell.items():
if isinstance(compound_dict[key_id], mb.Compound):
compound_to_move = compound_dict[key_id]
for pos in all_pos:
tmp_comp = mb.clone(compound_to_move)
tmp_comp.translate_to(list(pos))
ret_lattice.add(tmp_comp)
compoundsList.append(tmp_comp)
else:
err_type = type(compound_dict.get(key_id))
raise TypeError(
Expand All @@ -661,7 +662,7 @@ def populate(self, compound_dict=None, x=1, y=1, z=1):
warnings.warn(
f"Element assumed from cif file to be {element}.", UserWarning
)

ret_lattice.add(compoundsList)
# Create mbuild.box
ret_lattice.box = mb.Box(
lengths=[a * x, b * y, c * z], angles=self.angles
Expand Down
Loading