Skip to content

Commit

Permalink
In process
Browse files Browse the repository at this point in the history
  • Loading branch information
dprada committed Mar 21, 2024
1 parent 8c4b054 commit 2ed2474
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 40 deletions.
15 changes: 9 additions & 6 deletions molsysmt/_private/digestion/argument/bonded_atom_pairs.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
from molsysmt._private.exceptions import ArgumentError
from numpy import ndarray
import numpy as np

def digest_bonded_atom_pairs(bonded_atom_pairs, caller=None):

if caller=='molsysmt.basic.get.get':
if isinstance(bonded_atom_pairs, bool):
return bonded_atom_pairs
elif caller=='molsysmt.build.add_bonds.add_bonds':
elif caller.endswith('add_bonds.add_bonds'):
if isinstance(bonded_atom_pairs, list):
for sublist in bonded_atom_pairs:
if not (isinstance(sublist, list) and len(sublist) == 2):
raise ArgumentError('bonded_atom_pairs', value=bonded_atom_pairs, caller=caller, message=None)
if not all(isinstance(item, int) for item in sublist):
print('aa')
raise ArgumentError('bonded_atom_pairs', value=bonded_atom_pairs, caller=caller, message=None)
return bonded_atom_pairs
elif isinstance(bonded_atom_pairs, ndarray):
if

return np.array(bonded_atom_pairs)
elif isinstance(bonded_atom_pairs, np.ndarray):
if len(bonded_atom_pairs.shape)==2 and bonded_atom_pairs.shape[1]==2:
return bonded_atom_pairs
else:
raise ArgumentError('bonded_atom_pairs', value=bonded_atom_pairs, caller=caller, message=None)

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

23 changes: 20 additions & 3 deletions molsysmt/native/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ def _sort_bonds(self):
self.sort_values(by=['atom1_index', 'atom2_index'], inplace=True)
self.reset_index(drop=True, inplace=True)

def _remove_empty_columns(self):

if (self['order']=='nan').all():
del self['order']

if (self['type']=='nan').all():
del self['type']

class Topology():

Expand Down Expand Up @@ -316,8 +323,19 @@ def add_bonds(self, bonded_atom_pairs, skip_digestion=False):
aux_bonds_dataframe.atom1_index=bonded_atom_pairs[:,0]
aux_bonds_dataframe.atom2_index=bonded_atom_pairs[:,1]

df_concatenado = pd.concat([self.bonds, aux_bonds_dataframe], ignore_index=True)

self.bonds = Bonds_DataFrame(n_bonds=df_concatenado.shape[0])
self.bonds['atom1_index'] = df_concatenado['atom1_index']
self.bonds['atom2_index'] = df_concatenado['atom2_index']
self.bonds['order'] = df_concatenado['order']
self.bonds['type'] = df_concatenado['type']

self.bonds._sort_bonds()
self.bonds._remove_empty_columns()

del(df_concatenado, aux_bonds_dataframe)

df_concatenado = pd.concat([df_original, nuevas_filas], ignore_index=True)

def add_missing_bonds(self, selection='all', syntax='MolSysMT', skip_digestion=False):

Expand All @@ -327,8 +345,7 @@ def add_missing_bonds(self, selection='all', syntax='MolSysMT', skip_digestion=F
engine='MolSysMT', with_templates=True, with_distances=False,
skip_digestion=True)

self.bonds['atom1_index'] = np.array(bonds, dtype=int)[:,0]
self.bonds['atom2_index'] = np.array(bonds, dtype=int)[:,1]
self.add_bonds(bonds, skip_digestion=True)

def rebuild_atoms(self, redefine_ids=True, redefine_types=True):

Expand Down
74 changes: 43 additions & 31 deletions sandbox/Test_2nzt.ipynb

Large diffs are not rendered by default.

0 comments on commit 2ed2474

Please sign in to comment.