@@ -1347,7 +1347,7 @@ def clean_conformation_ff(
13471347 ff .SteepestDescent (10 )
13481348 ff .ConjugateGradients (10 )
13491349 ff .GetCoordinates (OBMol )
1350- coords , _ , _ = io_obabel .get_OBMol_coords_anums_graph (
1350+ coords , anums1 , _ = io_obabel .get_OBMol_coords_anums_graph (
13511351 OBMol , return_coords = True
13521352 )
13531353 # Reorder the coordinating atom assignment to more closely match unconstrained
@@ -1363,7 +1363,7 @@ def clean_conformation_ff(
13631363 ):
13641364 if debug :
13651365 print (
1366- "Finished initial UFF relaxation without angle constraints."
1366+ "Finished initial UFF relaxation without angle constraints.\n " ,
13671367 )
13681368 ff = openbabel .OBForceField .FindForceField ("UFF" )
13691369 constr = openbabel .OBFFConstraints ()
@@ -1596,7 +1596,7 @@ def set_position_align(
15961596 actual = np .array (
15971597 [np .asarray (init_posits [val [0 ]]) for val in ligcoordList ]
15981598 )
1599- if len (ideal ) > 2 :
1599+ if ( len (ideal ) > 2 ) and ( len ( ideal ) < 10 ) :
16001600 # Add reflection planes in case of mirrored molecule generated
16011601 mirrors = [[1 , 1 , 1 ], [- 1 , 1 , 1 ]] # Add mirror vectors
16021602 actual_mirrors = []
@@ -1658,12 +1658,55 @@ def set_position_align(
16581658 else :
16591659 for i , val in enumerate (mirrors [minind ]):
16601660 init_posits [:, i ] = val * init_posits [:, i ]
1661- elif len (ideal == 2 ): # No possible different symmetries here
1661+ elif len (ideal ) > 9 : # Do linear sum assignment for mirror rotations
1662+ mirrors = [[1 , 1 , 1 ], [- 1 , 1 , 1 ]] # Add mirror vectors
1663+ actual_mirrors = []
1664+ for mirror in mirrors :
1665+ actual_mirror = actual .copy ()
1666+ for i , val in enumerate (mirror ):
1667+ actual_mirror [:, i ] = val * actual_mirror [:, i ]
1668+ actual_mirrors .append (actual_mirror )
1669+ cost_mat0 = io_align_mol .permutation_cost_mat (
1670+ ideal ,
1671+ actual ,
1672+ ['a' ]* len (ideal ),
1673+ ['a' ]* len (actual ),
1674+ costtype = "xyz" )
1675+ cost_mat1 = io_align_mol .permutation_cost_mat (
1676+ ideal ,
1677+ actual_mirrors [0 ],
1678+ ['a' ]* len (ideal ),
1679+ ['a' ]* len (actual_mirrors [0 ]),
1680+ costtype = "xyz" )
1681+ cost_mat2 = io_align_mol .permutation_cost_mat (
1682+ ideal ,
1683+ actual_mirrors [1 ],
1684+ ['a' ]* len (ideal ),
1685+ ['a' ]* len (actual_mirrors [1 ]),
1686+ costtype = "xyz" )
1687+ permute0 = io_align_mol .linear_sum_assignment (cost_mat0 )[1 ]
1688+ permute1 = io_align_mol .linear_sum_assignment (cost_mat1 )[1 ]
1689+ permute2 = io_align_mol .linear_sum_assignment (cost_mat2 )[1 ]
1690+ align_0 = actual [permute0 ]
1691+ align_1 = actual_mirrors [0 ][permute1 ]
1692+ align_2 = actual_mirrors [1 ][permute2 ]
1693+ r0 = Rot .align_vectors (ideal , align_0 )
1694+ r1 = Rot .align_vectors (ideal , align_1 )
1695+ r2 = Rot .align_vectors (ideal , align_2 )
1696+ minval = r0 [1 ]
1697+ r = r0
1698+ if r1 [1 ] < minval :
1699+ r = r1
1700+ minval = r1 [1 ]
1701+ if r2 [1 ] < minval :
1702+ r = r2
1703+ minval = r2 [1 ]
1704+ elif len (ideal ) == 2 : # No possible different symmetries here
16621705 ideal = ideal
16631706 actual = actual
16641707 r = Rot .align_vectors (ideal , actual )
16651708 minval = r [1 ]
1666- elif len (ideal == 1 ) : # Just one!
1709+ elif len (ideal ) == 1 : # Just one!
16671710 ideal = ideal .reshape (1 , - 1 )
16681711 actual = actual .reshape (1 , - 1 )
16691712 r = Rot .align_vectors (ideal , actual )
@@ -2193,6 +2236,8 @@ def get_aligned_conformer(
21932236 ############# END FF Relaxation Section ##############
21942237
21952238 if not fail : # Catch FF optimization failures
2239+ if debug :
2240+ print ('Starting Alignment' )
21962241 (outatoms , minval , sane ) = set_position_align (
21972242 Conf3D_out ,
21982243 tligcoordList ,
@@ -2202,6 +2247,8 @@ def get_aligned_conformer(
22022247 rot_coord_vect = rot_coord_vect ,
22032248 rot_angle = rot_angle ,
22042249 )
2250+ if debug :
2251+ print ('Done Alignment' )
22052252 crowding_penalty = 0
22062253 if sane : # Perform check to see if metal is extra crowded.
22072254 cov1metal = cov1rad [- 1 ]
0 commit comments