Skip to content

Commit

Permalink
In process to refactor set chain_id to atoms
Browse files Browse the repository at this point in the history
  • Loading branch information
dprada committed Sep 20, 2023
1 parent 8c0c41b commit 94a02fa
Show file tree
Hide file tree
Showing 8 changed files with 329 additions and 154 deletions.
6 changes: 5 additions & 1 deletion molsysmt/_private/digestion/argument/chain_id.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from ...exceptions import ArgumentError
from ...variables import is_all

set_functions = (
'set.set',
'set_chain_id_to_atom')

def digest_chain_id(chain_id, caller=None):
"""Checks if `chain_id` has the expected type and value.
Expand Down Expand Up @@ -28,7 +32,7 @@ def digest_chain_id(chain_id, caller=None):
if caller=='molsysmt.basic.get.get':
if isinstance(chain_id, bool):
return chain_id
elif caller=='molsysmt.basic.set.set':
elif caller.endswith(set_functions):
if isinstance(chain_id, str):
return chain_id
elif caller.startswith('molsysmt.form.') and caller.count('.to_')==2:
Expand Down
4 changes: 3 additions & 1 deletion molsysmt/_private/digestion/digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def wrapper(*args, **kwargs):

all_args = argument_names_standardization(caller, all_args)


# Digestions:

digested_args = {}
Expand All @@ -102,13 +101,16 @@ def gut(arg_name):
not_digested_args[arg_name] = all_args[arg_name]
pass


for arg_name in all_args:
gut(arg_name)


for arg_name in not_digested_args:
if arg_name not in ['self']:
warnings.warn(arg_name+' from '+caller, NotDigestedArgumentWarning, stacklevel=2)


final_args = digested_args

if 'self' in all_args:
Expand Down
1 change: 0 additions & 1 deletion molsysmt/basic/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def set(molecular_system,
indices = select(molecular_system, element=element, selection=selection, syntax=syntax)

# doing the work here

for in_attribute in in_attributes:

dict_indices = {}
Expand Down
1 change: 1 addition & 0 deletions molsysmt/build/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
from .solvate import solvate
from .model_loop import model_loop
from .mutate import mutate
from .define_chain import define_chain

20 changes: 20 additions & 0 deletions molsysmt/build/define_chain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from molsysmt._private.digestion import digest
import numpy as np

@digest()
def define_chain(molecular_system, selection=None, id=None, name=None, syntax='MolSysMT'):
"""
To be written soon...
"""

from molsysmt.basic import get, set

former_id, former_name = get(molecular_system, element='chain', chain_id=True)

if id in former_id:
raise ValueError()

set(molecular_system, element='atom', selection=selection, syntax=syntax,
chain_id=id, chain_name=name)

pass
125 changes: 101 additions & 24 deletions molsysmt/form/molsysmt_Topology/set.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from molsysmt._private.digestion import digest
from molsysmt._private.variables import is_all
from molsysmt import pyunitwizard as puw
import numpy as np

Expand All @@ -11,168 +12,244 @@
@digest(form=form)
def set_atom_index_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'atom_index']=value
if is_all(indices):
item.atoms_dataframe['atom_index']=value
else:
item.atoms_dataframe.loc[indices, 'atom_index']=value

pass

@digest(form=form)
def set_atom_name_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'atom_name']=value
if is_all(indices):
item.atoms_dataframe['atom_name']=value
else:
item.atoms_dataframe.loc[indices, 'atom_name']=value

pass

@digest(form=form)
def set_atom_id_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'atom_id']=value
if is_all(indices):
item.atoms_dataframe['atom_id']=value
else:
item.atoms_dataframe.loc[indices, 'atom_id']=value

pass

@digest(form=form)
def set_atom_type_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'atom_type']=value
if is_all(indices):
item.atoms_dataframe['atom_type']=value
else:
item.atoms_dataframe.loc[indices, 'atom_type']=value

pass

@digest(form=form)
def set_group_index_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'group_index']=value
if is_all(indices):
item.atoms_dataframe['group_index']=value
else:
item.atoms_dataframe.loc[indices, 'group_index']=value

pass

@digest(form=form)
def set_group_name_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'group_name']=value
if is_all(indices):
item.atoms_dataframe['group_name']=value
else:
item.atoms_dataframe.loc[indices, 'group_name']=value

pass

@digest(form=form)
def set_group_id_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'group_id']=value
if is_all(indices):
item.atoms_dataframe['group_id']=value
else:
item.atoms_dataframe.loc[indices, 'group_id']=value

pass

@digest(form=form)
def set_group_type_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'group_type']=value
if is_all(indices):
item.atoms_dataframe['group_type']=value
else:
item.atoms_dataframe.loc[indices, 'group_type']=value

pass

@digest(form=form)
def set_component_index_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'component_index']=value
if is_all(indices):
item.atoms_dataframe['component_index']=value
else:
item.atoms_dataframe.loc[indices, 'component_index']=value

pass

@digest(form=form)
def set_component_name_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'component_name']=value
if is_all(indices):
item.atoms_dataframe['component_name']=value
else:
item.atoms_dataframe.loc[indices, 'component_name']=value

pass

@digest(form=form)
def set_component_id_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'component_id']=value
if is_all(indices):
item.atoms_dataframe['component_id']=value
else:
item.atoms_dataframe.loc[indices, 'component_id']=value

pass

@digest(form=form)
def set_component_type_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'component_type']=value
if is_all(indices):
item.atoms_dataframe['component_type']=value
else:
item.atoms_dataframe.loc[indices, 'component_type']=value

pass

@digest(form=form)
def set_molecule_index_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'molecule_index']=value
if is_all(indices):
item.atoms_dataframe['molecule_index']=value
else:
item.atoms_dataframe.loc[indices, 'molecule_index']=value

pass

@digest(form=form)
def set_molecule_name_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'molecule_name']=value
if is_all(indices):
item.atoms_dataframe['molecule_name']=value
else:
item.atoms_dataframe.loc[indices, 'molecule_name']=value

pass

@digest(form=form)
def set_molecule_id_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'molecule_id']=value
if is_all(indices):
item.atoms_dataframe['molecule_id']=value
else:
item.atoms_dataframe.loc[indices, 'molecule_id']=value

pass

@digest(form=form)
def set_molecule_type_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'molecule_type']=value
if is_all(indices):
item.atoms_dataframe['molecule_type']=value
else:
item.atoms_dataframe.loc[indices, 'molecule_type']=value

pass

@digest(form=form)
def set_chain_index_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'chain_index']=value
if is_all(indices):
item.atoms_dataframe['chain_index']=value
else:
item.atoms_dataframe.loc[indices, 'chain_index']=value

pass

@digest(form=form)
def set_chain_name_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'chain_name']=value
if is_all(indices):
item.atoms_dataframe['chain_name']=value
else:
item.atoms_dataframe.loc[indices, 'chain_name']=value

pass

@digest(form=form)
def set_chain_id_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'chain_id']=value
if is_all(indices):
item.atoms_dataframe['chain_id']=value
item.atoms_dataframe['chain_index']=0
else:
item.atoms_dataframe.loc[indices, 'chain_id']=value
aux_list = item.atoms_dataframe['chain_id'].unique()
for new_index, id for enumerate(aux_list):
item[item['chain_id']==id]=new_index

pass

@digest(form=form)
def set_chain_type_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'chain_type']=value
if is_all(indices):
item.atoms_dataframe['chain_type']=value
else:
item.atoms_dataframe.loc[indices, 'chain_type']=value

pass

@digest(form=form)
def set_entity_index_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'entity_index']=value
if is_all(indices):
item.atoms_dataframe['entity_index']=value
else:
item.atoms_dataframe.loc[indices, 'entity_index']=value

pass

@digest(form=form)
def set_entity_name_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'entity_name']=value
if is_all(indices):
item.atoms_dataframe['entity_name']=value
else:
item.atoms_dataframe.loc[indices, 'entity_name']=value

pass

@digest(form=form)
def set_entity_id_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'entity_id']=value
if is_all(indices):
item.atoms_dataframe['entity_id']=value
else:
item.atoms_dataframe.loc[indices, 'entity_id']=value

pass

@digest(form=form)
def set_entity_type_to_atom(item, indices='all', value=None):

item.atoms_dataframe.loc[indices, 'entity_type']=value
if is_all(indices):
item.atoms_dataframe['entity_type']=value
else:
item.atoms_dataframe.loc[indices, 'entity_type']=value

pass

Expand Down
Loading

0 comments on commit 94a02fa

Please sign in to comment.