Skip to content

Commit 751d696

Browse files
committed
updated regroup function during testing
1 parent 8d95ca8 commit 751d696

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

amx/gromacs/structure_tools.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,36 @@ def regroup(self):
180180
resnames_comp = list(zip(*state.composition))[0]
181181
if len(set(resnames_comp))!=len(resnames_comp):
182182
raise Exception('repeats in resnames %s'%resnames_comp)
183-
#! rename via special instructions
183+
#! rename via special instructions designed for some polmyers work
184184
rename_detected_composition = settings.get('rename_detected_composition')
185185
if rename_detected_composition:
186-
#! hacked backwards
186+
#! update development after refactor below
187+
print('finish refactor!')
188+
import ipdb;ipdb.set_trace()
189+
raise Exception('finish refactor')
190+
#! reversed the order here. rename_detected_composition may be used elsewhere?
187191
rename_detected_composition_r = dict([(j,i) for i,j in rename_detected_composition.items()])
188192
resnames_comp = [rename_detected_composition_r.get(i,i) for i in resnames_comp]
189-
# check that residue name lists are equivalent
190-
resnames,rn_inds = np.unique(self.residue_names,return_index=True)
191-
if set(resnames)!=set(resnames_comp):
193+
# generate residue,atom pairings
194+
pairings = np.transpose((self.residue_names,self.atom_names))
195+
# list of residue names where we include the atom name in the reordering
196+
groupable_residues = ['ION']
197+
# blank the atom names wherever the pairings
198+
pairings[np.where(~np.in1d(pairings[:,0],groupable_residues))[0],1] = ''
199+
# generate a canonical ordering method that accounts for possible aliases
200+
residues_unordered,residue_order = np.unique(pairings,return_index=True,axis=0)
201+
residue_pairs = residues_unordered[np.argsort(residue_order)]
202+
# we now have a list of residues, along with atom names if they are special
203+
residues_possible_structure = [i for i in residue_pairs.reshape(-1) if i]
204+
unmatched_residues = [i for i in resnames_comp if i not in residues_possible_structure]
205+
if any(unmatched_residues):
206+
# stop if any of the residue names in the composition do not match the structure
192207
raise Exception(
193-
'note that the composition %s does not match residue names in the structure %s'%(
194-
resnames_comp,resnames))
195-
reindexer = [np.where(self.residue_names==resname)[0] for resname in resnames]
208+
('we have residue (and atom, if applicable) pairs from the structure %s '
209+
'which do not match the composition/topology %s'%(
210+
residues_possible_structure,unmatched_residues)))
211+
# perform the re-indexing here
212+
reindexer = [np.where(np.all(pairings==pair,axis=1))[0] for pair in residue_pairs]
196213
natoms = sum([len(i) for i in reindexer])
197214
if natoms!=self.atom_names.shape[0]: raise Exception('atom count mismatch')
198215
reindexed = np.concatenate(reindexer)

0 commit comments

Comments
 (0)