Skip to content

Commit 1660df1

Browse files
committed
Fix formatting for tests
1 parent c0893a1 commit 1660df1

File tree

4 files changed

+97
-133
lines changed

4 files changed

+97
-133
lines changed

ensemble_md/replica_exchange_EE.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def set_params(self, analysis):
164164
"resname_transform": None,
165165
"resname_list": None,
166166
"swap_rep_pattern": None,
167+
"allow_virtual_V": False, # Allow use of V to indicate virtual atoms in topology
167168
"nst_sim": None,
168169
"proposal": 'exhaustive',
169170
"w_combine": False,
@@ -255,7 +256,7 @@ def set_params(self, analysis):
255256
if self.working_dir == '':
256257
self.working_dir = '.'
257258

258-
params_bool = ['verbose', 'rm_cpt', 'msm', 'free_energy', 'subsampling_avg', 'w_combine']
259+
params_bool = ['verbose', 'rm_cpt', 'msm', 'free_energy', 'subsampling_avg', 'w_combine', 'allow_virtual_V']
259260
for i in params_bool:
260261
if type(getattr(self, i)) != bool:
261262
raise ParameterError(f"The parameter '{i}' should be a boolean variable.")
@@ -1720,7 +1721,7 @@ def process_top(self):
17201721
function. Output as csv files to prevent needing to re-run this step.
17211722
"""
17221723
if not os.path.exists('atom_name_mapping.csv') and self.resname_list is not None:
1723-
coordinate_swap.create_atom_map(self.gro, self.resname_list, self.swap_rep_pattern)
1724+
coordinate_swap.create_atom_map(self.gro, self.resname_list, self.swap_rep_pattern, self.allow_virtual_V)
17241725
atom_name_mapping = pd.read_csv('atom_name_mapping.csv')
17251726
elif self.resname_list is not None:
17261727
atom_name_mapping = pd.read_csv('atom_name_mapping.csv')
Lines changed: 69 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,74 @@
11
,resname A,resname B,atomid A,atom name A,atomid B,atom name B
22
0,A2B,B2C,1,S1,1,S1
3-
1,A2B,B2C,1,S1,1,S1
4-
2,A2B,B2C,2,C2,2,C2
5-
3,A2B,B2C,2,C2,2,C2
6-
4,A2B,B2C,3,N3,3,N3
7-
5,A2B,B2C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7,7,C7
39-
13,B2C,C2D,7,C7,7,C7
40-
14,B2C,C2D,8,H1,9,H1
41-
15,B2C,C2D,8,H1,9,H1
42-
16,B2C,C2D,9,H2,10,H2
43-
17,B2C,C2D,9,H2,10,H2
44-
18,B2C,C2D,10,H3,11,H3
45-
19,B2C,C2D,10,H3,11,H3
46-
20,B2C,C2D,11,H4,12,H4
47-
21,B2C,C2D,11,H4,12,H4
48-
22,B2C,C2D,12,H5,19,HV5
49-
23,B2C,C2D,13,H6,13,H6
50-
24,B2C,C2D,13,H6,13,H6
51-
25,B2C,C2D,14,H7,14,H7
52-
26,B2C,C2D,14,H7,14,H7
53-
27,B2C,C2D,15,DC8,8,C8
54-
28,B2C,C2D,16,HV8,15,H8
55-
29,B2C,C2D,17,HV9,16,H9
56-
30,B2C,C2D,18,HV10,17,H10
17+
1,B2C,C2D,2,C2,2,C2
18+
2,B2C,C2D,3,N3,3,N3
19+
3,B2C,C2D,4,C4,4,C4
20+
4,B2C,C2D,5,C5,5,C5
21+
5,B2C,C2D,6,C6,6,C6
22+
6,B2C,C2D,7,C7,7,C7
23+
7,B2C,C2D,8,H1,9,H1
24+
8,B2C,C2D,9,H2,10,H2
25+
9,B2C,C2D,10,H3,11,H3
26+
10,B2C,C2D,11,H4,12,H4
27+
11,B2C,C2D,12,H5,19,HV5
28+
12,B2C,C2D,13,H6,13,H6
29+
13,B2C,C2D,14,H7,14,H7
30+
14,B2C,C2D,15,DC8,8,C8
31+
15,B2C,C2D,16,HV8,15,H8
32+
16,B2C,C2D,17,HV9,16,H9
33+
17,B2C,C2D,18,HV10,17,H10
5734
0,C2D,D2E,1,S1,1,S1
58-
1,C2D,D2E,1,S1,1,S1
59-
2,C2D,D2E,2,C2,2,C2
60-
3,C2D,D2E,2,C2,2,C2
61-
4,C2D,D2E,3,N3,3,N3
62-
5,C2D,D2E,3,N3,3,N3
63-
6,C2D,D2E,4,C4,4,C4
64-
7,C2D,D2E,4,C4,4,C4
65-
8,C2D,D2E,5,C5,5,C5
66-
9,C2D,D2E,5,C5,5,C5
67-
10,C2D,D2E,6,C6,6,C6
68-
11,C2D,D2E,6,C6,6,C6
69-
12,C2D,D2E,7,C7,7,C7
70-
13,C2D,D2E,7,C7,7,C7
71-
14,C2D,D2E,8,C8,18,DC8
72-
15,C2D,D2E,9,H1,9,H1
73-
16,C2D,D2E,9,H1,9,H1
74-
17,C2D,D2E,10,H2,10,H2
75-
18,C2D,D2E,10,H2,10,H2
76-
19,C2D,D2E,11,H3,11,H3
77-
20,C2D,D2E,11,H3,11,H3
78-
21,C2D,D2E,13,H6,13,H6
79-
22,C2D,D2E,13,H6,13,H6
80-
23,C2D,D2E,14,H7,14,H7
81-
24,C2D,D2E,14,H7,14,H7
82-
25,C2D,D2E,15,H8,19,HV8
83-
26,C2D,D2E,16,H9,20,HV9
84-
27,C2D,D2E,17,H10,21,HV10
85-
28,C2D,D2E,18,DC9,8,C9
86-
29,C2D,D2E,19,HV5,12,H5
87-
30,C2D,D2E,20,HV11,15,H11
88-
31,C2D,D2E,21,HV12,16,H12
89-
32,C2D,D2E,22,HV13,17,H13
35+
1,C2D,D2E,2,C2,2,C2
36+
2,C2D,D2E,3,N3,3,N3
37+
3,C2D,D2E,4,C4,4,C4
38+
4,C2D,D2E,5,C5,5,C5
39+
5,C2D,D2E,6,C6,6,C6
40+
6,C2D,D2E,7,C7,7,C7
41+
7,C2D,D2E,8,C8,18,DC8
42+
8,C2D,D2E,9,H1,9,H1
43+
9,C2D,D2E,10,H2,10,H2
44+
10,C2D,D2E,11,H3,11,H3
45+
11,C2D,D2E,13,H6,13,H6
46+
12,C2D,D2E,14,H7,14,H7
47+
13,C2D,D2E,15,H8,19,HV8
48+
14,C2D,D2E,16,H9,20,HV9
49+
15,C2D,D2E,17,H10,21,HV10
50+
16,C2D,D2E,18,DC9,8,C9
51+
17,C2D,D2E,19,HV5,12,H5
52+
18,C2D,D2E,20,HV11,15,H11
53+
19,C2D,D2E,21,HV12,16,H12
54+
20,C2D,D2E,22,HV13,17,H13
9055
0,D2E,E2F,1,S1,1,S1
91-
1,D2E,E2F,1,S1,1,S1
92-
2,D2E,E2F,2,C2,2,C2
93-
3,D2E,E2F,2,C2,2,C2
94-
4,D2E,E2F,3,N3,3,N3
95-
5,D2E,E2F,3,N3,3,N3
96-
6,D2E,E2F,4,C4,4,C4
97-
7,D2E,E2F,4,C4,4,C4
98-
8,D2E,E2F,5,C5,5,C5
99-
9,D2E,E2F,5,C5,5,C5
100-
10,D2E,E2F,6,C6,6,C6
101-
11,D2E,E2F,6,C6,6,C6
102-
12,D2E,E2F,7,C7,7,C7
103-
13,D2E,E2F,7,C7,7,C7
104-
14,D2E,E2F,8,C9,9,C9
105-
15,D2E,E2F,8,C9,9,C9
106-
16,D2E,E2F,9,H1,10,H1
107-
17,D2E,E2F,9,H1,10,H1
108-
18,D2E,E2F,10,H2,11,H2
109-
19,D2E,E2F,10,H2,11,H2
110-
20,D2E,E2F,11,H3,12,H3
111-
21,D2E,E2F,11,H3,12,H3
112-
22,D2E,E2F,13,H6,13,H6
113-
23,D2E,E2F,13,H6,13,H6
114-
24,D2E,E2F,14,H7,14,H7
115-
25,D2E,E2F,14,H7,14,H7
116-
26,D2E,E2F,15,H11,18,H11
117-
27,D2E,E2F,15,H11,18,H11
118-
28,D2E,E2F,16,H12,19,H12
119-
29,D2E,E2F,16,H12,19,H12
120-
30,D2E,E2F,17,H13,20,H13
121-
31,D2E,E2F,17,H13,20,H13
122-
32,D2E,E2F,18,DC8,8,C8
123-
33,D2E,E2F,19,HV8,15,H8
124-
34,D2E,E2F,20,HV9,16,H9
125-
35,D2E,E2F,21,HV10,17,H10
56+
1,D2E,E2F,2,C2,2,C2
57+
2,D2E,E2F,3,N3,3,N3
58+
3,D2E,E2F,4,C4,4,C4
59+
4,D2E,E2F,5,C5,5,C5
60+
5,D2E,E2F,6,C6,6,C6
61+
6,D2E,E2F,7,C7,7,C7
62+
7,D2E,E2F,8,C9,9,C9
63+
8,D2E,E2F,9,H1,10,H1
64+
9,D2E,E2F,10,H2,11,H2
65+
10,D2E,E2F,11,H3,12,H3
66+
11,D2E,E2F,13,H6,13,H6
67+
12,D2E,E2F,14,H7,14,H7
68+
13,D2E,E2F,15,H11,18,H11
69+
14,D2E,E2F,16,H12,19,H12
70+
15,D2E,E2F,17,H13,20,H13
71+
16,D2E,E2F,18,DC8,8,C8
72+
17,D2E,E2F,19,HV8,15,H8
73+
18,D2E,E2F,20,HV9,16,H9
74+
19,D2E,E2F,21,HV10,17,H10

ensemble_md/tests/test_coordinate_swap.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ def test_fix_break():
5858
broken_mol = md.load(f'{input_path}/coord_swap/broken_mol_1D.gro')
5959
df_connect = pd.read_csv(f'{input_path}/coord_swap/residue_connect.csv')
6060
df_connect_res = df_connect[df_connect['Resname'] == 'C2D']
61-
test_fix = coordinate_swap.fix_break(broken_mol, 'C2D', [2.74964, 2.74964, 2.74964], df_connect_res)
61+
test_fix = coordinate_swap.fix_break(broken_mol, 'C2D', [2.74964, 2.74964, 2.74964], df_connect_res, False, 1)
6262

6363
broken_mol_3D = md.load(f'{input_path}/coord_swap/broken_mol_3D.gro')
64-
test_fix_3D = coordinate_swap.fix_break(broken_mol_3D, 'C2D', [2.74964, 2.74964, 2.74964], df_connect_res)
64+
test_fix_3D = coordinate_swap.fix_break(broken_mol_3D, 'C2D', [2.74964, 2.74964, 2.74964], df_connect_res, False, 1)
6565

6666
already_fixed = md.load(f'{input_path}/coord_swap/fixed_mol.gro')
67-
still_fixed = coordinate_swap.fix_break(already_fixed, 'C2D', [2.74964, 2.74964, 2.74964], df_connect_res)
67+
still_fixed = coordinate_swap.fix_break(already_fixed, 'C2D', [2.74964, 2.74964, 2.74964], df_connect_res, False, 1)
6868

6969
fixed_mol = md.load(f'{input_path}/coord_swap/fixed_mol.gro')
7070

@@ -139,8 +139,8 @@ def test_get_miss_coord():
139139

140140
A_dimensions = coordinate_swap.get_dimensions(open(molA_file, 'r').readlines())
141141
B_dimensions = coordinate_swap.get_dimensions(open(molB_file, 'r').readlines())
142-
molA = coordinate_swap.fix_break(molA, nameA, A_dimensions, connection_map[connection_map['Resname'] == nameA])
143-
molB = coordinate_swap.fix_break(molB, nameB, B_dimensions, connection_map[connection_map['Resname'] == nameB])
142+
molA = coordinate_swap.fix_break(molA, nameA, A_dimensions, connection_map[connection_map['Resname'] == nameA], False)
143+
molB = coordinate_swap.fix_break(molB, nameB, B_dimensions, connection_map[connection_map['Resname'] == nameB], False)
144144

145145
df_no_coords = pd.read_csv(f'{input_path}/coord_swap/extract_missing.csv')
146146
df = pd.read_csv(f'{input_path}/coord_swap/df_atom_swap.csv')
@@ -273,7 +273,7 @@ def test_get_names():
273273
top_files = ['A-B.itp', 'B-C.itp', 'C-D.itp', 'D-E.itp', 'E-F.itp']
274274
resnames = ['A2B', 'B2C', 'C2D', 'D2E', 'E2F']
275275

276-
start_lines = [26, 29, 33, 32, 36]
276+
start_lines = [27, 30, 34, 33, 37]
277277
names = [['S1', 'C2', 'N3', 'C4', 'C5', 'C6', 'H1', 'H2', 'H3', 'H4', 'H17', 'DC7', 'HV5', 'HV6', 'HV7'], ['S1', 'C2', 'N3', 'C4', 'C5', 'C6', 'C7', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'DC8', 'HV8', 'HV9', 'HV10'], ['S1', 'C2', 'N3', 'C4', 'C5', 'C6', 'C7', 'C8', 'H1', 'H2', 'H3', 'H4', 'H6', 'H7', 'H8', 'H9', 'H10', 'DC9', 'HV5', 'HV11', 'HV12', 'HV13'], ['S1', 'C2', 'N3', 'C4', 'C5', 'C6', 'C7', 'C9', 'H1', 'H2', 'H3', 'H5', 'H6', 'H7', 'H11', 'H12', 'H13', 'DC8', 'HV8', 'HV9', 'HV10'], ['S1', 'C2', 'N3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'H1', 'H2', 'H3', 'H6', 'H7', 'H8', 'H9', 'H10', 'H11', 'H12', 'H13', 'DC10', 'HV4', 'HV14', 'HV15', 'HV16']] # noqa: E501
278278

279279
lambda_states = [[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 0, 0, 0, 0],
@@ -345,7 +345,7 @@ def test_create_atom_map():
345345
swap_pattern = [[[0, 1], [1, 0]], [[1, 1], [2, 0]], [[2, 1], [3, 0]], [[3, 1], [4, 0]]]
346346

347347
atom_name_mapping_true = pd.read_csv(f'{input_path}/coord_swap/atom_name_mapping.csv')
348-
coordinate_swap.create_atom_map(gro, names, swap_pattern)
348+
coordinate_swap.create_atom_map(gro, names, swap_pattern, True)
349349
atom_name_mapping_test = pd.read_csv('atom_name_mapping.csv')
350350
assert (atom_name_mapping_true == atom_name_mapping_test).all
351351
os.remove('atom_name_mapping.csv')

ensemble_md/utils/coordinate_swap.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ def fix_break(mol, resname, box_dimensions, atom_connect_all, verbose, resid=Non
106106
atom_connect_all : pandas.DataFrame
107107
A pandas DataFrame which contains the name of all atoms which are connected to one another
108108
in the residue of interest
109+
verbose : boolean
110+
Whether print statements should be made or not
111+
resid : None or int
112+
The reisude ID of the molecule of interest if multiple residues of the same name
109113
110114
Returns
111115
-------
@@ -989,14 +993,16 @@ def write_unmodified(line_start, orig_file, new_file, old_res_name, atom_num, pr
989993
return line_restart, atom_num_restart
990994

991995

992-
def _sep_num_element(atom_name):
996+
def _sep_num_element(atom_name, allow_virtual_V):
993997
"""
994998
Seperate the atom name into the element and the atom number
995999
9961000
Parameters
9971001
----------
9981002
atom_name : str
9991003
Name of the atom to be seperated
1004+
allow_virtual_V : bool
1005+
Should the use of a V to indicate virtual atoms be allowed
10001006
10011007
Returns
10021008
-------
@@ -1022,7 +1028,7 @@ def _sep_num_element(atom_name):
10221028
extra = ''.join(list(atom_identifier)[1:])
10231029
else:
10241030
extra = ''
1025-
if 'V' in extra:
1031+
if allow_virtual_V and 'V' in extra:
10261032
extra = extra.strip('V')
10271033
return element, num, extra
10281034

@@ -1246,7 +1252,7 @@ def _read_gro(side, resname_list, gro_list):
12461252
return name, num
12471253

12481254

1249-
def create_atom_map(gro_list, resname_list, swap_patterns):
1255+
def create_atom_map(gro_list, resname_list, swap_patterns, allow_virtual_V=False):
12501256
"""
12511257
If you generate your hybrid topologies in a way that the
12521258
same atom has the same name in each molecule then this
@@ -1260,6 +1266,8 @@ def create_atom_map(gro_list, resname_list, swap_patterns):
12601266
list of residue names with the transformation
12611267
swap_patterns : list of list of intergers
12621268
swapping pattern between simulations
1269+
allow_virtual_V : bool
1270+
Should the use of a V to indicate virtual atoms be allowed
12631271
12641272
Returns
12651273
-------
@@ -1272,7 +1280,7 @@ def create_atom_map(gro_list, resname_list, swap_patterns):
12721280

12731281
atomnameA, atomidA, atomnameB, atomidB = [], [], [], []
12741282
for n, name in enumerate(nameA):
1275-
element, num, extra = _sep_num_element(name)
1283+
element, num, extra = _sep_num_element(name, allow_virtual_V)
12761284
if name in nameB:
12771285
atomnameA.append(name)
12781286
atomidA.append(numA[n])
@@ -1291,6 +1299,12 @@ def create_atom_map(gro_list, resname_list, swap_patterns):
12911299
nb = nameB.index(f'D{element}{num}')
12921300
atomnameB.append(f'D{element}{num}')
12931301
atomidB.append(numB[nb])
1302+
elif allow_virtual_V is True and f'{element}V{num}' in nameB:
1303+
atomnameA.append(name)
1304+
atomidA.append(numA[n])
1305+
nb = nameB.index(f'{element}V{num}')
1306+
atomnameB.append(f'{element}V{num}')
1307+
atomidB.append(numB[nb])
12941308

12951309
df = pd.DataFrame({'resname A': resname_list[swap_pattern[0][0]], 'resname B': resname_list[swap_pattern[1][0]], 'atomid A': atomidA, 'atom name A': atomnameA, 'atomid B': atomidB, 'atom name B': atomnameB}) # noqa: E501
12961310
output_df = pd.concat([output_df, df])

0 commit comments

Comments
 (0)