2
2
import itertools
3
3
from cell2mol .cell_operations import translate
4
4
from cell2mol .other import additem , absolute_value
5
- from cell2mol .connectivity import compare_species , count_species , split_species
5
+ from cell2mol .connectivity import compare_species , count_species , split_species , arrange_data_for_reorder
6
+ from cell2mol .hungarian import reorder
6
7
from cell2mol .elementdata import ElementData
8
+ from cell2mol .read_write import writexyz
9
+
7
10
elemdatabase = ElementData ()
8
11
9
12
#######################################################
@@ -208,6 +211,9 @@ def fragments_reconstruct(moleclist: list, fraglist: list, Hlist: list, refmolec
208
211
moleclist .extend (finalmols )
209
212
print (f"{ finalmols = } " )
210
213
print (f"{ remfrag = } " )
214
+ for i , g in enumerate (finalmols ):
215
+ if debug == 1 : writexyz ("/Users/ycho/cell2mol/cell2mol/test/YOBCUO/" , f"reorder_molec_{ i } .xyz" , g .labels , g .coord )
216
+
211
217
if len (remfrag ) > 0 : Warning = True ; print ("FRAG_RECONSTRUCT. Remaining after Hydrogen reconstruction" ,remfrag )
212
218
else : Warning = False ; print ("FRAG_RECONSTRUCT. No remaining Molecules after Hydrogen reconstruction" )
213
219
elif len (remfrag ) > 0 and len (Hlist ) == 0 :
@@ -221,6 +227,7 @@ def fragments_reconstruct(moleclist: list, fraglist: list, Hlist: list, refmolec
221
227
# The former were identified in the cell.get_moleclist() function, and have cell as parent.
222
228
# The latter have been constructed by merging fragments, and do not have cell as parent, but have the cell_indices stored in mol.cell_indices
223
229
# Here we homogenize the situation by adding the cell_indices variable to all molecules
230
+ # TODO : why cell_indices is needed?
224
231
for mol in moleclist :
225
232
if not hasattr (mol ,"cell_indices" ):
226
233
if mol .check_parent ("cell" ):
@@ -466,6 +473,8 @@ def sequential(fragmentlist: list, refmoleclist: list, cellvec: list, factor: fl
466
473
467
474
#######################################################
468
475
def combine (tobemerged : list , references : list , cellvec : list , threshold_tmat : float , cov_factor : float , metal_factor : float , debug : int = 0 ):
476
+ from cell2mol .classes import molecule
477
+
469
478
goodlist = [] ## List of molecules coming from the two fragments received
470
479
avglist = [] ## List of bigger fragments coming from the two fragments received
471
480
badlist = [] ## List of fragments as they entered the function
@@ -488,12 +497,33 @@ def combine(tobemerged: list, references: list, cellvec: list, threshold_tmat: f
488
497
found = False
489
498
for ref in references :
490
499
if not found :
491
- issame = compare_species (newmolec , ref )
492
- if issame : ## Then is a molecule that appears in the reference list
493
- found = True
494
- newmolec .subtype = ref .subtype
495
- goodlist .append (newmolec )
496
- if debug >= 1 : print (f"COMBINE: Fragment { newmolec .formula } added to goodlist with { newmolec .cell_indices = } " )
500
+ if (newmolec .natoms == ref .natoms ) and (newmolec .eleccount == ref .eleccount ) and (newmolec .formula == ref .formula ):
501
+ dummy1 , dummy2 , map12 = reorder (ref .labels , newmolec .labels , ref .coord , newmolec .coord )
502
+
503
+ reordered_labels = [newmolec .labels [i ] for i in map12 ]
504
+ reordered_coord = [newmolec .coord [i ] for i in map12 ]
505
+ reordered_radii = [newmolec .radii [i ] for i in map12 ]
506
+ reordered_frac_cood = [newmolec .frac_coord [i ] for i in map12 ]
507
+ reordered_cell_indices = [newmolec .cell_indices [i ] for i in map12 ]
508
+
509
+ reordered_newmolec = molecule (reordered_labels , reordered_coord , reordered_radii )
510
+ reordered_newmolec .cell_indices = reordered_cell_indices
511
+ reordered_newmolec .set_fractional_coord (reordered_frac_cood )
512
+ reordered_newmolec .set_atoms (create_adjacencies = True , debug = 2 )
513
+ if reordered_newmolec .iscomplex :
514
+ reordered_newmolec .split_complex ()
515
+ reordered_newmolec .get_hapticity (debug = debug )
516
+ for lig in reordered_newmolec .ligands :
517
+ lig .get_denticity (debug = debug )
518
+
519
+ print (f"{ reordered_newmolec = } " )
520
+
521
+ issame = compare_species (reordered_newmolec , ref , debug = 2 )
522
+ if issame : ## Then is a molecule that appears in the reference list
523
+ found = True
524
+ reordered_newmolec .subtype = ref .subtype
525
+ goodlist .append (reordered_newmolec )
526
+ if debug >= 1 : print (f"COMBINE: Fragment { reordered_newmolec .formula } added to goodlist with { reordered_newmolec .cell_indices = } " )
497
527
if not found : ## Then it is a fragment. A bigger one, but still a fragment
498
528
newmolec .subtype = "Rec. Fragment"
499
529
avglist .append (newmolec )
0 commit comments