Skip to content

Commit

Permalink
in process
Browse files Browse the repository at this point in the history
  • Loading branch information
dprada committed Oct 24, 2023
1 parent fc27914 commit 7d8cf51
Show file tree
Hide file tree
Showing 15 changed files with 981 additions and 531 deletions.
14 changes: 11 additions & 3 deletions molsysmt/form/file_msmh5/is_form.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import PosixPath
import h5py
import os

def is_form(item):

Expand All @@ -11,9 +12,16 @@ def is_form(item):
if isinstance(item, str):
if item.endswith('.msmh5'):

with h5py.File(item, "r") as file:
if 'type' in file.attrs:
output = (file.attrs['type']=='msmh5')
if os.path.isfile(item):

with h5py.File(item, "r") as file:
if 'type' in file.attrs:
output = (file.attrs['type']=='msmh5')

else:

output = True

return output


10 changes: 9 additions & 1 deletion molsysmt/form/file_msmh5/to_molsysmt_Structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@
@digest(form='file:msmh5')
def to_molsysmt_Structures(item, atom_indices='all', structure_indices='all'):

raise NotImplementedError
from . import to_molsysmt_MSMH5FileHandler
from ..molsysmt_MSMH5FileHandler import to_molsysmt_Structures as molsysmt_MSMH5FileHandler_to_molsysmt_Structures

handler = to_molsysmt_MSMH5FileHandler(item)
tmp_item = molsysmt_MSMH5FileHandler_to_molsysmt_Structures(handler, atom_indices=atom_indices,
structure_indices=structure_indices)
handler.close()

return tmp_item
106 changes: 105 additions & 1 deletion molsysmt/form/molsysmt_MSMH5FileHandler/to_molsysmt_Structures.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,110 @@
from molsysmt._private.digestion import digest
from molsysmt import pyunitwizard as puw
import numpy as np

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

raise NotImplementedError
from molsysmt.native import Structures

structures_ds = item.file['structures']

n_atoms = structures_ds.attrs['n_atoms']
n_structures = structures_ds.attrs['n_structures']

length_unit = puw.unit(structures_ds.attrs['length_unit'])
time_unit = puw.unit(structures_ds.attrs['time_unit'])
energy_unit = puw.unit(structures_ds.attrs['energy_unit'])
temperature_unit = puw.unit(structures_ds.attrs['temperature_unit'])

standard_length_unit = puw.get_standard_units(length_unit)
standard_time_unit = puw.get_standard_units(time_unit)
standard_energy_unit = puw.get_standard_units(energy_unit)
standard_temperature_unit = puw.get_standard_units(temperature_unit)

tmp_item = Structures()

tmp_item.n_atoms = n_atoms
tmp_item.n_structures = n_structures

# Coordinates

if structures_ds['coordinates'].shape[0]>0:

tmp_item.coordinates = puw.quantity(np.zeros([n_structures, n_atoms, 3], dtype='float64'),
standard_length_unit)
tmp_item.coordinates[:,:,:] = puw.quantity(structures_ds['coordinates'][:,:,:],
length_unit)

else:

tmp_item.coordinates = None

# Velocities

if structures_ds['velocities'].shape[0]>0:

tmp_item.velocities = puw.quantity(np.zeros([n_structures, n_atoms, 3], dtype='float64'),
standard_length_unit/standard_time_unit)
tmp_item.velocities[:,:,:] = puw.quantity(structures_ds['velocities'][:,:,:],
length_unit/time_unit)

else:

tmp_item.velocities = None

# Box

if structures_ds['box'].shape[0]>0:

tmp_item.box = puw.quantity(np.zeros([n_structures, 3, 3], dtype='float64'),
standard_length_unit)
tmp_item.box[:,:,:] = puw.quantity(structures_ds['box'][:,:,:],
length_unit)

else:

tmp_item.box = None

# Kinetic Energy

if structures_ds['kinetic_energy'].shape[0]>0:

tmp_item.kinetic_energy = puw.quantity(np.zeros([n_structures], dtype='float64'),
standard_energy_unit)
tmp_item.kinetic_energy[:] = puw.quantity(structures_ds['kinetic_energy'][:],
energy_unit)

else:

tmp_item.kinetic_energy = None

# Potential Energy

if structures_ds['potential_energy'].shape[0]>0:

tmp_item.potential_energy = puw.quantity(np.zeros([n_structures], dtype='float64'),
standard_energy_unit)
tmp_item.potential_energy[:] = puw.quantity(structures_ds['potential_energy'][:],
energy_unit)

else:

tmp_item.potential_energy = None

# Temperature

if structures_ds['temperature'].shape[0]>0:

tmp_item.temperature = puw.quantity(np.zeros([n_structures], dtype='float64'),
standard_temperature_unit)
tmp_item.temperature[:] = puw.quantity(structures_ds['temperature'][:],
temperature_unit)

else:

tmp_item.temperature = None


return tmp_item

Loading

0 comments on commit 7d8cf51

Please sign in to comment.