Skip to content

Commit

Permalink
in process
Browse files Browse the repository at this point in the history
  • Loading branch information
dprada committed Oct 22, 2023
1 parent b2075ef commit 435d03b
Show file tree
Hide file tree
Showing 27 changed files with 1,128 additions and 83 deletions.
12 changes: 12 additions & 0 deletions molsysmt/_private/digestion/argument/compression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from molsysmt._private.exceptions import ArgumentError

def digest_compression(compression, caller=None):

if isinstance(compression, str):

if caller.endswith('to_file_msmh5'):
if compression in ['gzip', 'lzf', 'szip']:
return compression

raise ArgumentError('compression', value=compression, caller=caller, message=None)

12 changes: 12 additions & 0 deletions molsysmt/_private/digestion/argument/compression_opts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from molsysmt._private.exceptions import ArgumentError

def digest_compression_opts(compression_opts, caller=None):

if isinstance(compression_opts, int):

if caller.endswith('to_file_msmh5'):
if 0<=compression_opts<=9:
return compression_opts

raise ArgumentError('compression_opts', value=compression_opts, caller=caller, message=None)

12 changes: 12 additions & 0 deletions molsysmt/_private/digestion/argument/float_precision.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from molsysmt._private.exceptions import ArgumentError

def digest_float_precision(float_precision, caller=None):

if isinstance(float_precision, str):

if caller.endswith('to_file_msmh5'):
if float_precision in ['single', 'double']:
return float_precision

raise ArgumentError('float_precision', value=float_precision, caller=caller, message=None)

12 changes: 12 additions & 0 deletions molsysmt/_private/digestion/argument/int_precision.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from molsysmt._private.exceptions import ArgumentError

def digest_int_precision(int_precision, caller=None):

if isinstance(int_precision, str):

if caller.endswith('to_file_msmh5'):
if int_precision in ['single', 'double']:
return int_precision

raise ArgumentError('int_precision', value=int_precision, caller=caller, message=None)

2 changes: 2 additions & 0 deletions molsysmt/form/file_msmh5/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
from .set import *
from .iterators import StructuresIterator, TopologyIterator

from .to_molsysmt_MSMH5FileHandler import to_molsysmt_MSMH5FileHandler
from .to_molsysmt_MolSys import to_molsysmt_MolSys
from .to_molsysmt_Topology import to_molsysmt_Topology
from .to_molsysmt_Structures import to_molsysmt_Structures
from .to_nglview_NGLWidget import to_nglview_NGLWidget

_convert_to={
'file:msmh5': extract,
'molsysmt.MSMH5FileHandler': to_molsysmt_MSMH5FileHandler,
'molsysmt.MolSys': to_molsysmt_MolSys,
'molsysmt.Topology': to_molsysmt_Topology,
'molsysmt.Structures': to_molsysmt_Structures,
Expand Down
8 changes: 8 additions & 0 deletions molsysmt/form/file_msmh5/to_molsysmt_MSMH5FileHandler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from molsysmt._private.digestion import digest

@digest(form='file:msmh5')
def to_molsysmt_MSMH5FileHandler(item, atom_indices='all'):

from molsysmt.native import MSMH5FileHandler

return MSMH5FileHandler(item, io_mode='r')
9 changes: 8 additions & 1 deletion molsysmt/form/file_msmh5/to_molsysmt_Topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
@digest(form='file:msmh5')
def to_molsysmt_Topology(item, atom_indices='all'):

raise NotImplementedError
from . import to_molsysmt_MSMH5FileHandler
from ..molsysmt_MSMH5FileHandler import to_molsysmt_Topology as molsysmt_MSMH5FileHandler_to_molsysmt_Topology

handler = to_molsysmt_MSMH5FileHandler(item)
tmp_item = molsysmt_MSMH5FileHandler_to_molsysmt_Topology(handler, atom_indices=atom_indices)
handler.close()

return tmp_item
31 changes: 31 additions & 0 deletions molsysmt/form/molsysmt_MSMH5FileHandler/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
form_name = 'molsysmt.MSMH5FileHandler'
form_type = 'class'
form_info = ["", ""]

from .is_form import is_form

from .attributes import attributes
from .has_attribute import has_attribute

from .extract import extract
from .copy import copy
from .add import add
from .merge import merge
from .append_structures import append_structures
from .get import *
from .set import *
from .iterators import StructuresIterator, TopologyIterator

from .to_molsysmt_MolSys import to_molsysmt_MolSys
from .to_molsysmt_Topology import to_molsysmt_Topology
from .to_molsysmt_Structures import to_molsysmt_Structures
from .to_nglview_NGLWidget import to_nglview_NGLWidget

_convert_to={
'molsysmt.MSMH5FileHandler': extract,
'molsysmt.MolSys': to_molsysmt_MolSys,
'molsysmt.Topology': to_molsysmt_Topology,
'molsysmt.Structures': to_molsysmt_Structures,
'nglview.NGLWidget': to_nglview_NGLWidget,
}

8 changes: 8 additions & 0 deletions molsysmt/form/molsysmt_MSMH5FileHandler/add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from molsysmt._private.exceptions import NotImplementedMethodError
from molsysmt._private.digestion import digest

@digest(form='molsysmt.MSMH5FileHandler', to_form='molsysmt.MSMH5FileHandler')
def add(to_item, item, atom_indices='all', structure_indices='all'):

raise NotImplementedMethodError()

8 changes: 8 additions & 0 deletions molsysmt/form/molsysmt_MSMH5FileHandler/append_structures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from molsysmt._private.exceptions import NotImplementedMethodError
from molsysmt._private.digestion import digest

@digest(form='molsysmt.MSMH5FileHandler')
def append_structures(item, structure_id=None, time=None, coordinates=None, box=None):

raise NotImplementedMethodError()

39 changes: 39 additions & 0 deletions molsysmt/form/molsysmt_MSMH5FileHandler/attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from molsysmt.attribute.attributes import attributes as _all_attributes

attributes = {ii:False for ii in _all_attributes}

attributes['atom_index'] = True
attributes['atom_id'] = True
attributes['atom_name'] = True
attributes['atom_type'] = True
attributes['bond_index'] = True
attributes['bond_id'] = True
attributes['bond_type'] = True
attributes['bond_order'] = True
attributes['group_index'] = True
attributes['group_id'] = True
attributes['group_name'] = True
attributes['group_type'] = True
attributes['component_index'] = True
attributes['component_id'] = True
attributes['component_name'] = True
attributes['component_type'] = True
attributes['molecule_index'] = True
attributes['molecule_id'] = True
attributes['molecule_name'] = True
attributes['molecule_type'] = True
attributes['chain_index'] = True
attributes['chain_id'] = True
attributes['chain_name'] = True
attributes['chain_type'] = True
attributes['entity_index'] = True
attributes['entity_id'] = True
attributes['entity_name'] = True
attributes['entity_type'] = True
attributes['coordinates'] = True
attributes['velocities'] = True
attributes['box'] = True
attributes['time'] = True
attributes['structure_id'] = True

del(_all_attributes)
16 changes: 16 additions & 0 deletions molsysmt/form/molsysmt_MSMH5FileHandler/copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from molsysmt._private.exceptions import NotImplementedMethodError
from molsysmt._private.digestion import digest
from molsysmt._private.variables import is_all

@digest(form='molsysmt.MSMH5FileHandler')
def copy(item, output_filename=None):

if output_filename is None:
output_filename = item

from shutil import copy as copy_file
copy_file(item, output_filename)
tmp_item = output_filename

return tmp_item

27 changes: 27 additions & 0 deletions molsysmt/form/molsysmt_MSMH5FileHandler/extract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from molsysmt._private.exceptions import NotImplementedMethodError
from molsysmt._private.digestion import digest
from molsysmt._private.variables import is_all

@digest(form='molsysmt.MSMH5FileHandler')
def extract(item, atom_indices='all', structure_indices='all', output_filename=None, copy_if_all=True):

if output_filename is None:
output_filename = item

if is_all(atom_indices) and is_all(structure_indices):

if copy_if_all or (output_filename!=item):

from shutil import copy as copy_file
copy_file(item, output_filename)
tmp_item = output_filename

else:

tmp_item = item
else:

raise NotImplementedMethodError()

return tmp_item

Loading

0 comments on commit 435d03b

Please sign in to comment.