2121from itertools import product
2222import random
2323
24+
2425def get_dimensions (file ):
2526 """
2627 Determines the dimensions of the cubic box based on the input GRO file.
@@ -120,7 +121,7 @@ def fix_break(mol, resname, box_dimensions, atom_connect_all, verbose, resid=Non
120121 atom_pairs = []
121122 for atoms in atom_connect :
122123 if resid is not None :
123- atom_pairs .append (list (mol_top .select (f"resname { resname } and resid { resid - 1 } and (name { atoms [0 ]} or name { atoms [1 ]} )" )))
124+ atom_pairs .append (list (mol_top .select (f"resname { resname } and resid { resid - 1 } and (name { atoms [0 ]} or name { atoms [1 ]} )" ))) # noqa: E501
124125 else :
125126 atom_pairs .append (list (mol_top .select (f"resname { resname } and (name { atoms [0 ]} or name { atoms [1 ]} )" )))
126127
@@ -380,7 +381,7 @@ def get_miss_coord(mol_align, mol_ref, name_align, name_ref, df_atom_swap, dir,
380381 return df_atom_swap
381382
382383
383- def get_miss_coord_by_num (mol_target , mol_ref , select_name , transform_name , dir , np_target , list_ref , list_ref_trans , name_list , df_atom_swap ):
384+ def get_miss_coord_by_num (mol_target , mol_ref , select_name , transform_name , dir , np_target , list_ref , list_ref_trans , name_list , df_atom_swap ): # noqa: E501
384385 """
385386 Gets coordinates for the missing atoms after the conformational swap
386387
@@ -420,7 +421,7 @@ def get_miss_coord_by_num(mol_target, mol_ref, select_name, transform_name, dir,
420421 df_atom_swap ['Y Coordinates' ] = np .nan
421422 df_atom_swap ['Z Coordinates' ] = np .nan
422423
423- # In the case where the target system has fewer of the molecule of interest then the reference just select molecule at random and use the coordinates
424+ # In the case where the target system has fewer of the molecule of interest then the reference just select molecule at random and use the coordinates # noqa: E501
424425 # Step 2: Determine which molecules will correspond to which after the swap
425426 if len (np_target ) <= len (list_ref ):
426427 adding_molecules = False
@@ -434,7 +435,7 @@ def get_miss_coord_by_num(mol_target, mol_ref, select_name, transform_name, dir,
434435 # Step 3: Get coordinates for each atom for molecules determined above
435436 np_target_remaining = copy .deepcopy (np_target )
436437 target_real = []
437- atom_counter = 0 # Keep track of when we move to the next resid number
438+ atom_counter = 0 # Keep track of when we move to the next resid number
438439 for i , row in df_atom_swap [df_atom_swap ['Swap' ] == dir ].iterrows ():
439440 if row ['Resname' ] == select_name or adding_molecules is False :
440441 target_resid = int (row ['Resid' ])
@@ -450,7 +451,7 @@ def get_miss_coord_by_num(mol_target, mol_ref, select_name, transform_name, dir,
450451 atom_counter += 1
451452 atomname = row ['Name' ]
452453 atomid = mol_ref .topology .select (f'resid { ref_resid - 1 } and name { atomname } ' )[0 ]
453- coords = mol_ref .xyz [0 ,atomid ,:]
454+ coords = mol_ref .xyz [0 , atomid , :]
454455
455456 df_atom_swap .at [i , 'X Coordinates' ] = coords [0 ]
456457 df_atom_swap .at [i , 'Y Coordinates' ] = coords [1 ]
@@ -459,17 +460,14 @@ def get_miss_coord_by_num(mol_target, mol_ref, select_name, transform_name, dir,
459460 if adding_molecules is False :
460461 return df_atom_swap
461462
462- # In the case where the target has more of a molecule than the reference we need to get new coordinates
463- num_add = len (np_target ) - len (list_ref )
464- added = 0
465- attempt = 0
463+ # In the case where the target has more of a molecule than the reference we need to get new coordinates
466464 # Step 4: Align select atoms between the two systems
467465 while len (np_target_remaining ) != 0 :
468466 # Step 5: select coordinates for atom and add to DF
469467 sele_resid_add = np_target_remaining [0 ]
470468 np_target_remaining = np .delete (np_target_remaining , 0 )
471469 for n , name in enumerate (name_list ):
472- index_add = df_atom_swap [(df_atom_swap ['Swap' ] == dir ) & (df_atom_swap ['Resid' ] == sele_resid_add ) & (df_atom_swap ['Name' ] == name )].index [0 ]
470+ index_add = df_atom_swap [(df_atom_swap ['Swap' ] == dir ) & (df_atom_swap ['Resid' ] == sele_resid_add ) & (df_atom_swap ['Name' ] == name )].index [0 ] # noqa: E501
473471 index_traj = mol_target .topology .select (f'resid { sele_resid_add - 1 } and name { name } ' )[0 ]
474472 new_coords = mol_target .xyz [0 , index_traj , :]
475473 if n == 0 :
@@ -1102,7 +1100,7 @@ def get_names(input, resname):
11021100 if line == '[ atoms ]\n ' :
11031101 atom_section = True
11041102 if line == '[ bonds ]\n ' :
1105- start_line = l + 2
1103+ start_line = l + 2
11061104 return start_line , atom_name , np .array (atom_num ), state
11071105
11081106
@@ -1241,7 +1239,6 @@ def _read_gro(side, resname_list, gro_list):
12411239 name .append (line [9 :15 ].replace (' ' , '' ))
12421240 num .append (line [15 :20 ])
12431241
1244-
12451242 return name , num
12461243
12471244
@@ -1296,6 +1293,7 @@ def create_atom_map(gro_list, resname_list, swap_patterns):
12961293 output_df .reindex ()
12971294 output_df .to_csv ('atom_name_mapping.csv' )
12981295
1296+
12991297def deter_num_molecule (gro , name , trans_name ):
13001298 """
13011299 Determine the number of molecules with this name in the system
@@ -1331,4 +1329,4 @@ def deter_num_molecule(gro, name, trans_name):
13311329 if num not in trans_res_mol :
13321330 trans_res_mol .append (num )
13331331 num_mol = len (res_mol ) + len (trans_res_mol )
1334- return num_mol , res_mol , trans_res_mol
1332+ return num_mol , res_mol , trans_res_mol
0 commit comments