Skip to content

Commit fee12fd

Browse files
committed
fix linting
1 parent 623dfad commit fee12fd

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

ensemble_md/replica_exchange_EE.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def set_params(self, analysis):
460460
self.modify_coords_fn = self.default_coords_fn
461461
elif self.modify_coords == 'number':
462462
if self.resname_select is None or self.resname_transform is None:
463-
raise ParameterError('resname_select and resname_transform options must be filled in if using the change number function')
463+
raise ParameterError('resname_select and resname_transform options must be filled in if using the change number function') # noqa: E501
464464
# Read file
465465
input_file = gmx_parser.read_top(self.top[-1], self.resname_transform)
466466
# Determine the atom names corresponding to the atom numbers
@@ -1765,7 +1765,7 @@ def process_top(self):
17651765
start_line, atom_name, atom_num, state = coordinate_swap.get_names(input_file, resname)
17661766

17671767
# Determine the connectivity of all atoms
1768-
connect_1, connect_2 = [], [] # Atom 1 and atom 2 which are connected and which state they are dummy atoms # noqa: E501
1768+
connect_1, connect_2 = [], [] # Atom 1 and atom 2 which are connected and which state they are dummy atoms # noqa: E501
17691769
for l, line in enumerate(input_file[start_line:]): # noqa: E741
17701770
line_sep = line.split(' ')
17711771
if line_sep[0] == ';':
@@ -1845,8 +1845,8 @@ def change_num(self, molA_file_name, molB_file_name, swap_index):
18451845
molA_new = open(molA_new_file_name, 'w')
18461846

18471847
# Step 2: Determine how many of the molecule of interest are present in each system
1848-
numA, listA, trans_listA = coordinate_swap.deter_num_molecule(molA_file_name, self.resname_select, self.resname_transform)
1849-
numB, listB, trans_listB = coordinate_swap.deter_num_molecule(molB_file_name, self.resname_select, self.resname_transform)
1848+
numA, listA, trans_listA = coordinate_swap.deter_num_molecule(molA_file_name, self.resname_select, self.resname_transform) # noqa: E501
1849+
numB, listB, trans_listB = coordinate_swap.deter_num_molecule(molB_file_name, self.resname_select, self.resname_transform) # noqa: E501
18501850

18511851
# Step 3: Fix break if present for solvated systems only
18521852
if len(molA.topology.select('water')) != 0:
@@ -1862,7 +1862,7 @@ def change_num(self, molA_file_name, molB_file_name, swap_index):
18621862
molB = coordinate_swap.fix_break(molB, self.resname_transform, B_dimensions, connection_map[connection_map['Resname'] == self.resname_transform], self.verbose, resid) # noqa: E501
18631863

18641864
# Step 3: Setup the coordinate DF for the molecules
1865-
name, resid, resname, swap = [],[],[],[]
1865+
name, resid, resname, swap = [], [], [], []
18661866
for i in listA:
18671867
for n in self.atom_names:
18681868
name.append(n)
@@ -1887,7 +1887,7 @@ def change_num(self, molA_file_name, molB_file_name, swap_index):
18871887
resid.append(i)
18881888
resname.append(self.resname_transform)
18891889
swap.append('A2B')
1890-
df_atom_swap = pd.DataFrame({'Name': name, 'Resid': resid, 'Resname': resname,'Swap': swap})
1890+
df_atom_swap = pd.DataFrame({'Name': name, 'Resid': resid, 'Resname': resname, 'Swap': swap})
18911891

18921892
# Step 4: Determine coordinates of all residues of interest # noqa: E501
18931893
df_atom_swap = coordinate_swap.get_miss_coord_by_num(molB, molA, self.resname_select, self.resname_transform, 'A2B', np.array(listB+trans_listB), listA, trans_listA, self.atom_names, df_atom_swap) # noqa: E501
@@ -1917,7 +1917,7 @@ def change_num(self, molA_file_name, molB_file_name, swap_index):
19171917
while line_start < len(molA_file):
19181918
if line_start is not None:
19191919
# Print up until we reach the residue to modify
1920-
line_start, atom_num_restart = coordinate_swap.write_unmodified(line_start, molA_file, molB_new,resname_opt, atom_num_restart, preamble_legth, molA_coords, resnum_restart) # noqa: E501
1920+
line_start, atom_num_restart = coordinate_swap.write_unmodified(line_start, molA_file, molB_new, resname_opt, atom_num_restart, preamble_legth, molA_coords, resnum_restart) # noqa: E501
19211921
else:
19221922
break
19231923

@@ -1957,4 +1957,4 @@ def change_num(self, molA_file_name, molB_file_name, swap_index):
19571957

19581958
# Rename temp files
19591959
os.rename('A_hybrid_swap.gro', molB_dir + '/confout.gro')
1960-
os.rename('B_hybrid_swap.gro', molA_dir + '/confout.gro')
1960+
os.rename('B_hybrid_swap.gro', molA_dir + '/confout.gro')

ensemble_md/utils/coordinate_swap.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from itertools import product
2222
import random
2323

24+
2425
def 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+
12991297
def 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

ensemble_md/utils/gmx_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,9 @@ def deter_atom_order(mol_file, resname, resid=None):
439439
else:
440440
resname_list = resname
441441
resid_list = resid
442-
442+
443443
atom_order_all = []
444-
for resname_i, resid_i in zip(resname_list, resid_list):
444+
for resname_i, resid_i in zip(resname_list, resid_list):
445445
atom_order = []
446446
for line in mol_file:
447447
split_line = line.split(' ')

0 commit comments

Comments
 (0)