Skip to content

Commit

Permalink
Some modifications to nglview functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dprada committed Dec 29, 2024
1 parent 44dca96 commit 8c2b1e0
Show file tree
Hide file tree
Showing 11 changed files with 614 additions and 178 deletions.
3 changes: 3 additions & 0 deletions molsysmt/_private/digestion/argument/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ def digest_color(color, caller=None):
if len(color)==3:
return color

if isinstance(color, str):
return color

raise ArgumentError('color', value=color, caller=caller, message=None)
44 changes: 31 additions & 13 deletions molsysmt/structure/least_rmsd_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
@digest()
def least_rmsd_align(molecular_system, selection='atom_name=="CA"', structure_indices='all',
reference_molecular_system=None, reference_selection=None, reference_structure_index=0,
syntax='MolSysMT',
engine_sequence_alignment = 'Biopython', engine_least_rmsd_fit = 'MolSysMT'):
syntax='MolSysMT', engine_sequence_alignment = 'Biopython', engine_least_rmsd_fit = 'MolSysMT',
in_place=False, skip_digestion=False):

"""
To be written soon...
"""
Expand Down Expand Up @@ -49,21 +50,38 @@ def least_rmsd_align(molecular_system, selection='atom_name=="CA"', structure_in

from molsysmt.structure import least_rmsd_fit

output = least_rmsd_fit(molecular_system=molecular_system, selection=atoms_in_components_selected,
selection_fit=selection_to_be_fitted,
structure_indices=structure_indices, reference_molecular_system=reference_molecular_system,
reference_selection_fit=reference_selection_to_be_fitted,
reference_structure_index=reference_structure_index,
to_form=None, in_place=False, engine='MolSysMT', syntax=syntax)
if in_place:

least_rmsd_fit(molecular_system=molecular_system, selection=atoms_in_components_selected,
selection_fit=selection_to_be_fitted,
structure_indices=structure_indices, reference_molecular_system=reference_molecular_system,
reference_selection_fit=reference_selection_to_be_fitted,
reference_structure_index=reference_structure_index,
to_form=None, in_place=in_place, engine='MolSysMT', syntax=syntax, skip_digestion=True)

del(atoms_in_components_selected, selection_to_be_fitted, reference_selection_to_be_fitted)
del(structure_indices, reference_structure_index)

gc.collect()

else:

del(atoms_in_components_selected, selection_to_be_fitted, reference_selection_to_be_fitted)
del(structure_indices, reference_structure_index)
output = least_rmsd_fit(molecular_system=molecular_system, selection=atoms_in_components_selected,
selection_fit=selection_to_be_fitted,
structure_indices=structure_indices, reference_molecular_system=reference_molecular_system,
reference_selection_fit=reference_selection_to_be_fitted,
reference_structure_index=reference_structure_index,
to_form=None, in_place=in_place, engine='MolSysMT', syntax=syntax, skip_digestion=True)

del(atoms_in_components_selected, selection_to_be_fitted, reference_selection_to_be_fitted)
del(structure_indices, reference_structure_index)

gc.collect()

return output

else:

raise NotImplementedMethodError

gc.collect()

return output

2 changes: 1 addition & 1 deletion molsysmt/structure/least_rmsd_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@digest()
def least_rmsd_fit(molecular_system=None, selection='all', selection_fit='atom_type!="H"', structure_indices='all',
reference_molecular_system=None, reference_selection_fit=None, reference_structure_index=0,
to_form=None, in_place=False, syntax='MolSysMT', engine='MolSysMT'):
to_form=None, in_place=False, syntax='MolSysMT', engine='MolSysMT', skip_digestion=False):
"""
To be written soon...
"""
Expand Down
5 changes: 4 additions & 1 deletion molsysmt/thirds/nglview/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from .patching_nglview import adding_molsysmt

from .show_gui import show_gui
from .clear import clear

from .color_by_value import color_by_value
from .set_color import set_color
from .set_color_by_value import set_color_by_value

from .load_html_in_jupyter_notebook import load_html_in_jupyter_notebook
from .write_html import write_html
Expand All @@ -12,6 +14,7 @@
from .show_as_surface import show_as_surface
from .show_as_licorice import show_as_licorice
from .show_as_balls_and_sticks import show_as_balls_and_sticks
from .show_as_cartoon import show_as_cartoon

from .add_cylinders import add_cylinders
from .add_contacts import add_contacts
Expand Down
13 changes: 13 additions & 0 deletions molsysmt/thirds/nglview/clear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from molsysmt._private.digestion import digest
from molsysmt._private.variables import is_all

# https://github.com/arose/ngl/blob/master/doc/usage/selection-language.md


@digest(form='nglview.NGLWidget')
def clear(view, skip_digestion=False):

view.clear_representations()

pass

14 changes: 14 additions & 0 deletions molsysmt/thirds/nglview/set_color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from molsysmt._private.digestion import digest
from molsysmt._private.variables import is_all

# https://github.com/arose/ngl/blob/master/doc/usage/selection-language.md

@digest()
def set_color(view, color, selection='all', syntax='MolSysMT'):

from molsysmt.basic import select

atoms_selection = select(view, element='atom', selection=selection, syntax=syntax, to_syntax='NGLView')
view.update_representation(component=0, selection=atoms_selection, color=color)

pass
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# https://github.com/arose/ngl/blob/master/doc/usage/selection-language.md

@digest()
def color_by_value(view, values, element='group', selection='all', cmap='bwr_r',
def set_color_by_value(view, values, element='group', selection='all', cmap='bwr_r',
min_value=None, max_value=None, representation='cartoon', syntax='MolSysMT'):
"""Adding a new representation colored by a color scale.
Expand Down
27 changes: 27 additions & 0 deletions molsysmt/thirds/nglview/show_as_cartoon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from molsysmt._private.digestion import digest
from molsysmt._private.variables import is_all

# https://github.com/arose/ngl/blob/master/doc/usage/selection-language.md


@digest(form='nglview.NGLWidget')
def show_as_cartoon(view, selection='all', color='blue', skip_digestion=False):

from molsysmt import select

nglview_selection=None

if isinstance(selection, str):
if selection=='molecule_type=="water"' or selection=='group_type=="water"':
nglview_selection='water'
if selection=='molecule_type=="ion"' or selection=='group_type=="ion"':
nglview_selection='ion'

if nglview_selection is None:
nglview_selection = select(view, element='atom', selection=selection, to_syntax='NGLView',
skip_digestion=True)

view.add_cartoon(selection=nglview_selection, color=color)

pass

Loading

0 comments on commit 8c2b1e0

Please sign in to comment.