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

Do not add auxiliary cell to uploaded/generated structures #592

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
40 changes: 5 additions & 35 deletions aiidalab_widgets_base/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,32 +384,6 @@ def __init__(
children=[self.file_upload, supported_formats, self._status_message]
)

def _validate_and_fix_ase_cell(self, ase_structure, vacuum_ang=10.0):
"""
Checks if the ase Atoms object has a cell set,
otherwise sets it to bounding box plus specified "vacuum" space
"""
if not ase_structure:
return None

cell = ase_structure.cell

# TODO: Since AiiDA 2.0, zero cell is possible if PBC=false
# so we should honor that here and do not put artificial cell
# around gas phase molecules.
if (
np.linalg.norm(cell[0]) < 0.1
or np.linalg.norm(cell[1]) < 0.1
or np.linalg.norm(cell[2]) < 0.1
):
# if any of the cell vectors is too short, consider it faulty
# set cell as bounding box + vacuum_ang
bbox = np.ptp(ase_structure.positions, axis=0)
new_structure = ase_structure.copy()
new_structure.cell = bbox + vacuum_ang
return new_structure
return ase_structure

def _on_file_upload(self, change=None):
"""When file upload button is pressed."""
for fname, item in change["new"].items():
Expand Down Expand Up @@ -451,10 +425,7 @@ def _read_structure(self, fname, content):
if self.allow_trajectories:
return TrajectoryData(
structurelist=[
StructureData(
ase=self._validate_and_fix_ase_cell(ase_struct)
)
for ase_struct in structures
StructureData(ase=ase_struct) for ase_struct in structures
]
)
else:
Expand All @@ -463,7 +434,7 @@ def _read_structure(self, fname, content):
"""
return None

return self._validate_and_fix_ase_cell(structures[0])
return structures[0]


class StructureExamplesWidget(ipw.VBox):
Expand Down Expand Up @@ -683,7 +654,7 @@ def _on_select_structure(self, _=None):


class SmilesWidget(ipw.VBox):
"""Convert SMILES into 3D structure."""
"""Convert SMILES into a 3D structure."""

structure = tl.Instance(ase.Atoms, allow_none=True)

Expand All @@ -698,8 +669,9 @@ def __init__(self, title=""):
super().__init__(
[
ipw.HTML(
"The SmilesWidget requires the rdkit library, "
"The SMILES widget requires the rdkit library, "
"but the library was not found."
"You can install it with <code>pip install rdkit<code>"
)
]
)
Expand All @@ -726,12 +698,10 @@ def _make_ase(self, species, positions, smiles):
if len(species) > 2:
positions = PCA(n_components=3).fit_transform(positions)
atoms = ase.Atoms(species, positions=positions, pbc=False)
atoms.cell = np.ptp(atoms.positions, axis=0) + 10
atoms.center()
# We're attaching this info so that it
# can be later stored as an extra on AiiDA Structure node.
atoms.info["smiles"] = smiles

return atoms

def _rdkit_opt(self, smiles, steps):
Expand Down
Loading