Skip to content

Commit

Permalink
In process
Browse files Browse the repository at this point in the history
  • Loading branch information
dprada committed Mar 12, 2024
1 parent 8d3aab8 commit dd23817
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 61 deletions.
3 changes: 1 addition & 2 deletions molsysmt/_private/digestion/argument/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def digest_box(box, caller=None):
else:
raise ArgumentError('box', value=box, caller=caller, message=None)

box = puw.quantity(box_value, box_unit)
box = puw.standardize(box)
box = puw.quantity(box_value, box_unit, standardized=True)

return box

21 changes: 20 additions & 1 deletion molsysmt/_private/digestion/argument/box_angles.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,24 @@ def digest_box_angles(box_angles, caller=None):
if not puw.check(box_angles, dimensionality={}):
raise ArgumentError('box_angles', value=box_angles, caller=caller, message=None)

return puw.standardize(box_angles)
value, unit = puw.get_value_and_unit(box_angles)

if not isinstance(value, np.ndarray):
value = np.array(value)

shape = value.shape

if len(shape) == 1:
if shape[0] != 3:
raise ArgumentError('box_angles', caller=caller, message=None)
value = np.expand_dims(value, axis=0)
elif len(shape) == 2:
if shape[1] != 3:
raise ArgumentError('box_angles', value=box_angles, caller=caller, message=None)
else:
raise ArgumentError('box_angles', value=box_angles, caller=caller, message=None)

box_angles = puw.quantity(value, unit, standardized=True)

return box_angles

21 changes: 20 additions & 1 deletion molsysmt/_private/digestion/argument/box_lengths.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,24 @@ def digest_box_lengths(box_lengths, caller=None):
if not puw.check(box_lengths, dimensionality={'[L]':1}):
raise ArgumentError('box_lengths', value=box_lengths, caller=caller, message=None)

return puw.standardize(box_lengths)
value, unit = puw.get_value_and_unit(box_lengths)

if not isinstance(value, np.ndarray):
value = np.array(value)

shape = value.shape

if len(shape) == 1:
if shape[0] != 3:
raise ArgumentError('box_lengths', caller=caller, message=None)
value = np.expand_dims(value, axis=0)
elif len(shape) == 2:
if shape[1] != 3:
raise ArgumentError('box_lengths', value=box_lengths, caller=caller, message=None)
else:
raise ArgumentError('box_lengths', value=box_lengths, caller=caller, message=None)

box_lengths = puw.quantity(value, unit, standardized=True)

return box_lengths

17 changes: 9 additions & 8 deletions molsysmt/form/file_pdb/to_molsysmt_MolSys.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from molsysmt._private.digestion import digest

@digest(form='file:pdb')
def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', skip_digestion=False):
def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', get_missing_bonds=False,
skip_digestion=False):

from molsysmt.native import MolSys
from . import to_molsysmt_Topology
from . import to_molsysmt_Structures
from . import to_molsysmt_PDBFileHandler
from ..molsysmt_PDBFileHandler import to_molsysmt_MolSys as molsysmt_PDBFileHandler_to_molsysmt_MolSys

tmp_item = MolSys()
tmp_item.topology = to_molsysmt_Topology(item, atom_indices=atom_indices, skip_digestion=True)
tmp_item.structures = to_molsysmt_Structures(item, atom_indices=atom_indices,
structure_indices=structure_indices, skip_digestion=True)
tmp_item = to_molsysmt_PDBFileHandler(item, skip_digestion=True)
tmp_item = molsysmt_PDBFileHandler_to_molsysmt_MolSys(tmp_item, atom_indices=atom_indices,
structure_indices=structure_indices,
get_missing_bonds=get_missing_bonds,
skip_digestion=True)

return tmp_item

16 changes: 13 additions & 3 deletions molsysmt/form/molsysmt_PDBFileHandler/to_molsysmt_MolSys.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', get_mi
occupancy_array = np.array(occupancy_array, dtype=float)
alternate_location_array = np.array(alternate_location_array, dtype=str)

coordinates_array = np.array(coordinates_array, dtype=float)

alt_atom_indices = np.where(alternate_location_array!=' ')[0]
aux_dict = {}

Expand Down Expand Up @@ -132,9 +134,15 @@ def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', get_mi
cryst1 = item.entry.crystallographic_and_coordinate_transformation.cryst1
box_lengths = puw.quantity([[cryst1.a, cryst1.b, cryst1.c]], 'angstroms')
box_angles = puw.quantity([[cryst1.alpha, cryst1.beta, cryst1.gamma]], 'degrees')
print(box_lengths, box_angles)
box = get_box_from_lengths_and_angles(box_lengths, box_angles)
print(box)
box = get_box_from_lengths_and_angles(box_lengths, box_angles, skip_digestion=True)

coordinates = puw.quantity(coordinates_array, 'angstroms')
tmp_item.structures.append(coordinates=coordinates, box=box)

del(coordinates_array, box, box_lengths, box_angles)
del(atom_id_array, atom_name_array, group_index_array, chain_index_array,
group_id_array, group_name_array, chain_name_array, occupancy_array,
alternate_location_array, alt_atom_indices, aux_dict)

if get_missing_bonds:

Expand All @@ -145,6 +153,8 @@ def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', get_mi
tmp_item.topology.bonds.atom1_index=bonds[:,0]
tmp_item.topology.bonds.atom2_index=bonds[:,1]

del(bonds)

tmp_item.topology.rebuild_components()
tmp_item.topology.rebuild_molecules()
tmp_item.topology.rebuild_chains(redefine_ids=False, redefine_types=True)
Expand Down
Loading

0 comments on commit dd23817

Please sign in to comment.