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

Fix/traitlet structure fixes #381 blocked by #377 #383

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e3ce568
draft
cpignedoli Oct 14, 2022
6768950
work in progress
cpignedoli Oct 15, 2022
445a3aa
first working version, to-do: add/remove atoms in edit structure
cpignedoli Oct 15, 2022
06a6f12
comments
cpignedoli Oct 15, 2022
9cea518
toward general formalism
cpignedoli Oct 16, 2022
1ea7067
starting modifiying addition and rmeova of atoms
cpignedoli Oct 16, 2022
5a12592
intermediate mess
cpignedoli Oct 17, 2022
f652396
used same concept of fragments for representations
cpignedoli Oct 17, 2022
469ef53
reordering representation class
cpignedoli Oct 17, 2022
9749526
first draft working
cpignedoli Oct 17, 2022
4670934
redesigned, debug prints present
cpignedoli Oct 18, 2022
83cbc81
refinements
cpignedoli Oct 18, 2022
c8006b6
use dtratlet input_structure
cpignedoli Oct 19, 2022
3d642d1
version for first evaluation
cpignedoli Oct 19, 2022
090b94a
problem of syncronization of arrays in structure traitlet
cpignedoli Oct 21, 2022
8467ce6
updated validate structure
cpignedoli Oct 21, 2022
745e6cb
Fixed bug of representrations not passed
cpignedoli Oct 21, 2022
e0f5318
default -1 for arrays['representations'] for atoms not included in a rep
cpignedoli Oct 21, 2022
a04e32c
added show of representations
cpignedoli Oct 21, 2022
755a6a4
modification
cpignedoli Oct 21, 2022
3ae05c3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 21, 2022
2957cef
simplifying to single component
cpignedoli Oct 22, 2022
f3d6310
bug fix
cpignedoli Oct 22, 2022
861c45d
bug fix
cpignedoli Oct 22, 2022
1a1ce85
strange ngl problme
cpignedoli Oct 23, 2022
bf627bb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 23, 2022
c73fc68
first working version
cpignedoli Oct 24, 2022
8e86ecb
exclude from adavnced selection atoms not shown
cpignedoli Oct 24, 2022
fec6d9a
cleaning
cpignedoli Oct 24, 2022
9c19ecb
cleaning, removed orient_z_up to be put in separate PR
cpignedoli Oct 24, 2022
e475724
implementing bonds computed via ase. still buggy in handling shape
cpignedoli Oct 26, 2022
1fa17ca
bug fix
cpignedoli Oct 27, 2022
d73d7f7
restyling
cpignedoli Oct 27, 2022
727858f
mic distance for cylinders in bonds
cpignedoli Oct 28, 2022
9f1a5d8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 28, 2022
72d6f3c
adjusted bonds for edges of periodic box
cpignedoli Oct 28, 2022
59ef7b3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 28, 2022
02edbde
added info on representations
cpignedoli Nov 4, 2022
bc179c4
set structure to None when action on importer and in
cpignedoli Nov 12, 2022
89b1023
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 12, 2022
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
18 changes: 18 additions & 0 deletions aiidalab_widgets_base/dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,21 @@
"Hs": 1.75,
"Mt": 1.75,
}

RGB_colors = {
"red": [1, 0, 0],
"green": [0, 1, 0],
"blue": [0, 0, 1],
"yellow": [1, 1, 0],
"cyan": [0, 1, 1],
"magenta": [1, 0, 1],
"white": [1, 1, 1],
"black": [0, 0, 0],
"grey": [0.5, 0.5, 0.5],
"purple": [0.5, 0, 0.5],
"orange": [1, 0.5, 0],
"brown": [0.5, 0.25, 0],
"pink": [1, 0.75, 0.8],
"lime": [0.75, 1, 0],
"olive": [0.5, 0.5, 0],
}
38 changes: 29 additions & 9 deletions aiidalab_widgets_base/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __init__(
self.viewer = viewer
else:
self.viewer = StructureDataViewer(**kwargs)
dlink((self, "structure_node"), (self.viewer, "structure"))
dlink((self, "structure"), (self.viewer, "structure"))

# Store button.
self.btn_store = ipw.Button(description="Store in AiiDA", disabled=True)
Expand Down Expand Up @@ -159,6 +159,7 @@ def _structure_importers(self, importers):
if len(importers) == 1:
# Assigning a function which will be called when importer provides a structure.
dlink((importers[0], "structure"), (self, "input_structure"))

return importers[0]

# Otherwise making one tab per importer.
Expand Down Expand Up @@ -315,6 +316,7 @@ def _observe_input_structure(self, change):
# If the `input_structure` trait is set to Atoms object, then the `structure` trait should be set to it as well.
self.history = []

self.structure = None
if isinstance(change["new"], Atoms):
self.structure = change["new"]

Expand All @@ -330,16 +332,14 @@ def _observe_input_structure(self, change):
elif isinstance(change["new"], StructureData):
self.structure = change["new"].get_ase()

else:
self.structure = None

@observe("structure")
def _structure_changed(self, change=None):
"""Perform some operations that depend on the value of `structure` trait.

This function enables/disables `btn_store` widget if structure is provided/set to None.
Also, the function sets `structure_node` trait to the selected node type.
"""

if not self.structure_set_by_undo:
self.history.append(change["new"])

Expand Down Expand Up @@ -408,6 +408,7 @@ def _validate_and_fix_ase_cell(self, ase_structure, vacuum_ang=10.0):

def _on_file_upload(self, change=None):
"""When file upload button is pressed."""
self.structure = None
for fname, item in change["new"].items():
self.structure = self._read_structure(fname, item["content"])
self.file_upload.value.clear()
Expand Down Expand Up @@ -801,6 +802,7 @@ def _on_button_pressed(self, change): # pylint: disable=unused-argument
"""Convert SMILES to ase structure when button is pressed."""
self.output.value = ""

self.structure = None
if not self.smiles.value:
return
spinner = f"Screening possible conformers {self.SPINNER}" # font-size:20em;
Expand Down Expand Up @@ -1182,6 +1184,12 @@ def disable_element(_=None):
]
)

def find_index(self, list_of_lists, element):
for i, x in enumerate(list_of_lists):
if element in x:
return i
return -1

def str2vec(self, string):
return np.array(list(map(float, string.split())))

Expand Down Expand Up @@ -1371,6 +1379,7 @@ def mod_element(self, _=None, atoms=None, selection=None):
initial_ligand = self.ligand.rotate(
align_to=self.action_vector, remove_anchor=True
)

for idx in self.selection:
position = self.structure.positions[idx].copy()
lgnd = initial_ligand.copy()
Expand All @@ -1380,7 +1389,10 @@ def mod_element(self, _=None, atoms=None, selection=None):
i for i in range(last_atom, last_atom + len(selection) * len(lgnd))
]

self.structure, self.selection = atoms, new_selection
# the order of the traitlets below is important
# we must be sure trait atoms is set BEFORE trait selection
self.structure = atoms
self.selection = new_selection

@_register_structure
@_register_selection
Expand All @@ -1395,14 +1407,16 @@ def copy_sel(self, _=None, atoms=None, selection=None):

new_selection = [i for i in range(last_atom, last_atom + len(selection))]

self.structure, self.selection = atoms, new_selection
# the order of the traitlets below is important
# we must be sure trait atoms is set BEFORE trait selection
self.structure = atoms
self.selection = new_selection

@_register_structure
@_register_selection
def add(self, _=None, atoms=None, selection=None):
"""Add atoms."""
last_atom = atoms.get_global_number_of_atoms()

if self.ligand.value == 0:
initial_ligand = Atoms([Atom(self.element.value, [0, 0, 0])])
rad = SYMBOL_RADIUS[self.element.value]
Expand Down Expand Up @@ -1430,12 +1444,18 @@ def add(self, _=None, atoms=None, selection=None):
i for i in range(last_atom, last_atom + len(selection) * len(lgnd))
]

self.structure, self.selection = atoms, new_selection
# the order of the traitlets below is important
# we must be sure trait atoms is set BEFORE trait selection
self.structure = atoms
self.selection = new_selection

@_register_structure
@_register_selection
def remove(self, _, atoms=None, selection=None):
"""Remove selected atoms."""
del [atoms[selection]]

self.structure, self.selection = atoms, list()
# the order of the traitlets below is important
# we must be sure trait atoms is set BEFORE trait selection
self.selection = []
self.structure = atoms
Loading