Skip to content

Commit

Permalink
Revise the GRO file writting step for coordinate modification
Browse files Browse the repository at this point in the history
  • Loading branch information
ajfriedman22 committed Oct 10, 2024
1 parent 18042b5 commit 2fcee10
Show file tree
Hide file tree
Showing 14 changed files with 265 additions and 136 deletions.
9 changes: 7 additions & 2 deletions ensemble_md/replica_exchange_EE.py
Original file line number Diff line number Diff line change
Expand Up @@ -1565,18 +1565,23 @@ def default_coords_fn(self, molA_file_name, molB_file_name):
if len(miss_A) != 0:
df_atom_swap = coordinate_swap.get_miss_coord(molA, molB, nameA, nameB, df_atom_swap, 'A2B', swap_map[(swap_map['Swap A'] == nameA) & (swap_map['Swap B'] == nameB)]) # noqa: E501

# Step 5: Parse Current file to ensure atoms are added in the correct order
atom_order_A = gmx_parser.deter_atom_order(molA_file, nameA)
atom_order_B = gmx_parser.deter_atom_order(molB_file, nameB)

# Step 6: Write the new file
# Reprint preamble text
line_start = coordinate_swap.print_preamble(molA_file, molB_new, len(miss_B), len(miss_A))

# Print new coordinates to file for molB
coordinate_swap.write_new_file(df_atom_swap, 'A2B', 'B2A', line_start, molA_file, molB_new, nameA, nameB, copy.deepcopy(molA.xyz[0]), miss_A) # noqa: E501
coordinate_swap.write_new_file(df_atom_swap, 'A2B', 'B2A', line_start, molA_file, molB_new, nameA, nameB, copy.deepcopy(molA.xyz[0]), miss_A, atom_order_B) # noqa: E501

# Print new coordinates to file
# Reprint preamble text
line_start = coordinate_swap.print_preamble(molB_file, molA_new, len(miss_A), len(miss_B))

# Print new coordinates for molA
coordinate_swap.write_new_file(df_atom_swap, 'B2A', 'A2B', line_start, molB_file, molA_new, nameB, nameA, copy.deepcopy(molB.xyz[0]), miss_B) # noqa: E501
coordinate_swap.write_new_file(df_atom_swap, 'B2A', 'A2B', line_start, molB_file, molA_new, nameB, nameA, copy.deepcopy(molB.xyz[0]), miss_B, atom_order_A) # noqa: E501

# Rename temp files
os.rename('A_hybrid_swap.gro', molB_dir + '/confout.gro')
Expand Down
23 changes: 23 additions & 0 deletions ensemble_md/tests/data/coord_swap/output_C.gro
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Protein in water
20
1I2J O 1 5.0178633 5.0861511 2.3039777 0.000 0.000 0.000
1I2J C1 2 5.0669813 5.1162391 2.4148340 0.000 0.000 0.000
1I2J C2 3 5.1077561 5.2565174 2.4496574 0.000 0.000 0.000
1I2J C3 4 5.2587881 5.2859540 2.4412327 0.000 0.000 0.000
1I2J C4 5 5.3591075 5.2250023 2.5407770 0.000 0.000 0.000
1I2J CV5 6 5.5062575 5.2488542 2.5104387 0.000 0.000 0.000
1I2J CV6 7 5.5972819 5.1913514 2.6236000 0.000 0.000 0.000
1I2J H1 8 5.0745454 5.0403323 2.4957850 0.000 0.000 0.000
1I2J H2 9 5.0574427 5.3244996 2.3799186 0.000 0.000 0.000
1I2J H3 10 5.0872545 5.2717891 2.5562549 0.000 0.000 0.000
1I2J H4 11 5.2938070 5.2602854 2.3405781 0.000 0.000 0.000
1I2J H5 12 5.2689505 5.3949656 2.4466877 0.000 0.000 0.000
1I2J H6 13 5.3415952 5.1181459 2.5578511 0.000 0.000 0.000
1I2J H7 14 5.3279910 5.2632923 2.6386654 0.000 0.000 0.000
1I2J H8 15 5.4598603 5.2642937 2.5228457 0.000 0.000 0.000
1I2J HV9 16 5.5342641 5.2074494 2.4128795 0.000 0.000 0.000
1I2J HV10 17 5.5161352 5.3577881 2.5176795 0.000 0.000 0.000
1I2J HV11 18 5.7024980 5.1972165 2.5934060 0.000 0.000 0.000
1I2J HV12 19 5.5721917 5.0852852 2.6353056 0.000 0.000 0.000
1I2J HV13 20 5.5869956 5.2427306 2.7198856 0.000 0.000 0.000
7.06448 7.06448 4.99534 0.00000 0.00000 0.00000 0.00000 3.53224 3.53224
29 changes: 29 additions & 0 deletions ensemble_md/tests/data/coord_swap/output_D.gro
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Protein in water
26
1J2K O 1 5.2959995 4.9607749 2.2057471 0.000 0.000 0.000
1J2K C1 2 5.2068386 4.9330115 2.2914972 0.000 0.000 0.000
1J2K C2 3 5.2367387 4.9143419 2.4417152 0.000 0.000 0.000
1J2K C3 4 5.2398911 5.0504713 2.5114973 0.000 0.000 0.000
1J2K C4 5 5.1193190 5.1436095 2.4967213 0.000 0.000 0.000
1J2K C5 6 4.9869380 5.0971766 2.5653727 0.000 0.000 0.000
1J2K C6 7 4.8737483 5.2045283 2.5777171 0.000 0.000 0.000
1J2K CV7 8 4.9173560 5.3224721 2.6708064 0.000 0.000 0.000
1J2K CV8 9 4.8892651 5.2975769 2.8232861 0.000 0.000 0.000
1J2K H1 10 5.1009479 4.9196019 2.2602017 0.000 0.000 0.000
1J2K H2 11 5.1548157 4.8529458 2.4809031 0.000 0.000 0.000
1J2K H3 12 5.3377852 4.8729944 2.4515378 0.000 0.000 0.000
1J2K H4 13 5.2431130 5.0364089 2.6201639 0.000 0.000 0.000
1J2K H5 14 5.3289862 5.1061687 2.4802494 0.000 0.000 0.000
1J2K H6 15 5.0852985 5.1476994 2.3925943 0.000 0.000 0.000
1J2K H7 16 5.1522965 5.2398167 2.5376258 0.000 0.000 0.000
1J2K H9 17 4.9479947 5.0155101 2.5034811 0.000 0.000 0.000
1J2K H10 18 4.9996490 5.0553794 2.6659110 0.000 0.000 0.000
1J2K H11 19 4.7855296 5.1634459 2.6281769 0.000 0.000 0.000
1J2K H12 20 4.8469658 5.2264252 2.4736989 0.000 0.000 0.000
1J2K H13 21 4.9016318 5.2935543 2.6352797 0.000 0.000 0.000
1J2K HV14 21 5.0237503 5.3428926 2.6540799 0.000 0.000 0.000
1J2K HV15 22 4.8513546 5.4049191 2.6414304 0.000 0.000 0.000
1J2K HV16 23 4.9280410 5.2066817 2.8707309 0.000 0.000 0.000
1J2K HV17 24 4.9172225 5.3824968 2.8867180 0.000 0.000 0.000
1J2K HV18 25 4.7816763 5.2949572 2.8441288 0.000 0.000 0.000
6.81420 6.81420 4.81837 0.00000 0.00000 0.00000 0.00000 3.40710 3.40710
45 changes: 45 additions & 0 deletions ensemble_md/tests/data/coord_swap/residue_connect_alt.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
,Resname,Connect 1,Connect 2,State 1,State 2
0,I2J,O,C1,-1,-1
1,I2J,C1,C2,-1,-1
2,I2J,C1,H1,-1,-1
3,I2J,C2,C3,-1,-1
4,I2J,C2,H2,-1,-1
5,I2J,C2,H3,-1,-1
6,I2J,C3,C4,-1,-1
7,I2J,C3,H4,-1,-1
8,I2J,C3,H5,-1,-1
9,I2J,C4,CV5,-1,0
10,I2J,C4,H6,-1,-1
11,I2J,C4,H7,-1,-1
12,I2J,C4,H8,-1,1
13,I2J,CV5,CV6,0,0
14,I2J,CV5,HV9,0,0
15,I2J,CV5,HV10,0,0
16,I2J,CV6,HV11,0,0
17,I2J,CV6,HV12,0,0
18,I2J,CV6,HV13,0,0
0,J2K,O,C1,-1,-1
1,J2K,C1,C2,-1,-1
2,J2K,C1,H1,-1,-1
3,J2K,C2,C3,-1,-1
4,J2K,C2,H2,-1,-1
5,J2K,C2,H3,-1,-1
6,J2K,C3,C4,-1,-1
7,J2K,C3,H4,-1,-1
8,J2K,C3,H5,-1,-1
9,J2K,C4,C5,-1,-1
10,J2K,C4,H6,-1,-1
11,J2K,C4,H7,-1,-1
12,J2K,C5,C6,-1,-1
13,J2K,C5,H9,-1,-1
14,J2K,C5,H10,-1,-1
15,J2K,C6,CV7,-1,0
16,J2K,C6,H11,-1,-1
17,J2K,C6,H12,-1,-1
18,J2K,C6,H13,-1,1
19,J2K,CV7,CV8,0,0
20,J2K,CV7,HV14,0,0
21,J2K,CV7,HV15,0,0
22,J2K,CV8,HV16,0,0
23,J2K,CV8,HV17,0,0
24,J2K,CV8,HV18,0,0
3 changes: 3 additions & 0 deletions ensemble_md/tests/data/coord_swap/residue_swap_map_alt.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
,Swap A,Swap B,Anchor Atom Name A,Anchor Atom Name B,Alignment Atom A,Alignment Atom B,Angle Atom A,Angle Atom B,Missing Atom Name
0,I2J,J2K,C4,C4,CV5,C5,C3,C3,H8
0,J2K,I2J,C6,CV6,H13,HV13,C5,CV5,CV7 CV8 HV14 HV15 HV16 HV17 HV18
23 changes: 23 additions & 0 deletions ensemble_md/tests/data/coord_swap/sim_C/confout_backup.gro
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Protein in water
20
1I2J O 1 5.296 4.961 2.206 -0.3686 0.3444 -0.1300
1I2J C1 2 5.207 4.933 2.291 -0.2138 0.6863 0.8740
1I2J C2 3 5.237 4.914 2.442 -0.1897 -0.2629 -0.3198
1I2J C3 4 5.240 5.050 2.511 0.0930 -0.1426 -0.5485
1I2J C4 5 5.119 5.144 2.497 -0.4009 0.0472 0.1513
1I2J CV5 6 4.987 5.097 2.565 0.0543 0.1262 0.2260
1I2J CV6 7 4.874 5.205 2.578 0.9132 -0.3592 -0.0244
1I2J H1 8 5.101 4.920 2.260 -0.0394 2.2014 -0.3651
1I2J H2 9 5.155 4.853 2.481 0.6299 -1.3414 -0.2963
1I2J H3 10 5.338 4.873 2.452 -0.7490 -1.7256 -0.7240
1I2J H4 11 5.243 5.036 2.620 0.3644 -4.1763 -1.0785
1I2J H5 12 5.329 5.106 2.480 1.2963 -0.7568 1.7877
1I2J H6 13 5.085 5.148 2.393 1.4662 -0.9628 -0.4984
1I2J H7 14 5.152 5.240 2.538 1.5196 -0.0617 -1.1409
1I2J H8 15 5.039 5.112 2.564 0.5121 0.3042 1.3585
1I2J HV9 16 4.948 5.016 2.503 1.3134 0.4465 -0.9890
1I2J HV10 17 5.000 5.055 2.666 -1.9137 -1.0343 -0.0077
1I2J HV11 18 4.786 5.163 2.628 0.6018 -0.1023 -0.3595
1I2J HV12 19 4.847 5.226 2.474 -1.7867 0.1242 0.7725
1I2J HV13 20 4.902 5.294 2.635 -0.4338 0.4864 -0.6797
6.81420 6.81420 4.81837 0.00000 0.00000 0.00000 0.00000 3.40710 3.40710
Binary file added ensemble_md/tests/data/coord_swap/sim_C/traj.trr
Binary file not shown.
29 changes: 29 additions & 0 deletions ensemble_md/tests/data/coord_swap/sim_D/confout_backup.gro
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Protein in water
26
1J2K O 1 5.018 5.086 2.304 0.1745 0.5890 -0.1758
1J2K C1 2 5.067 5.116 2.415 -0.2291 -0.2305 0.2929
1J2K C2 3 5.108 5.257 2.450 -0.5244 -0.1122 0.0621
1J2K C3 4 5.259 5.286 2.441 -0.2349 -0.3584 -0.6547
1J2K C4 5 5.359 5.225 2.541 0.2423 -0.3055 0.0402
1J2K C5 6 5.506 5.249 2.510 -0.3200 0.3017 0.4568
1J2K C6 7 5.597 5.191 2.624 0.0359 0.2685 0.3027
1J2K CV7 8 5.569 5.267 2.757 0.3904 -0.1473 0.0832
1J2K CV8 9 5.468 5.387 2.743 -0.2666 -0.4050 -0.2619
1J2K H1 10 5.075 5.040 2.496 -2.0271 -2.3023 -1.4818
1J2K H2 11 5.057 5.324 2.380 -0.3736 2.2840 2.2892
1J2K H3 12 5.087 5.272 2.556 -0.2398 -0.7192 0.2037
1J2K H4 13 5.294 5.260 2.341 -1.2738 0.9886 -1.3596
1J2K H5 14 5.269 5.395 2.447 0.5557 -0.5016 0.7326
1J2K H6 15 5.342 5.118 2.558 1.2103 -0.6961 -1.4115
1J2K H7 16 5.328 5.263 2.639 3.1608 0.2336 0.7570
1J2K H9 17 5.534 5.207 2.413 3.0729 0.7986 1.2199
1J2K H10 18 5.516 5.358 2.518 0.7974 0.2313 -0.0088
1J2K H11 19 5.702 5.197 2.593 -0.1152 0.8857 -0.1042
1J2K H12 20 5.572 5.085 2.635 1.2100 0.1165 1.4424
1J2K H13 21 5.587 5.243 2.720 0.8334 -1.0594 1.0965
1J2K HV14 22 5.533 5.195 2.832 0.0741 -1.2105 -1.1017
1J2K HV15 23 5.665 5.313 2.783 -0.1626 1.8344 -1.3512
1J2K HV16 24 5.369 5.369 2.698 0.8667 -0.4618 -2.6960
1J2K HV17 25 5.451 5.441 2.837 -0.9029 1.3592 -1.3936
1J2K HV18 26 5.510 5.468 2.683 1.4067 0.5534 2.2296
7.06448 7.06448 4.99534 0.00000 0.00000 0.00000 0.00000 3.53224 3.53224
Binary file added ensemble_md/tests/data/coord_swap/sim_D/traj.trr
Binary file not shown.
16 changes: 15 additions & 1 deletion ensemble_md/tests/test_replica_exchange_EE.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ def test_default_coords_fn(self, params_dict):
REXEE = get_REXEE_instance(params_dict)
os.system(f'cp {input_path}/coord_swap/residue_connect.csv .')
os.system(f'cp {input_path}/coord_swap/residue_swap_map.csv .')
REXEE.default_coords_fn(f'{input_path}/coord_swap/sim_A/confout.gro', f'{input_path}/coord_swap/sim_B/confout.gro') # noqa: E501
REXEE.default_coords_fn(f'{input_path}/coord_swap/sim_A/confout_backup.gro', f'{input_path}/coord_swap/sim_B/confout_backup.gro') # noqa: E501

true_output_A = open(f'{input_path}/coord_swap/output_A.gro', 'r').readlines()
test_output_A = open(f'{input_path}/coord_swap/sim_B/confout.gro', 'r').readlines()
Expand All @@ -905,6 +905,20 @@ def test_default_coords_fn(self, params_dict):
assert true_output_A == test_output_A
assert true_output_B == test_output_B

os.system(f'cp {input_path}/coord_swap/residue_connect_alt.csv residue_connect.csv')
os.system(f'cp {input_path}/coord_swap/residue_swap_map_alt.csv residue_swap_map.csv')
REXEE.default_coords_fn(f'{input_path}/coord_swap/sim_C/confout_backup.gro', f'{input_path}/coord_swap/sim_D/confout_backup.gro') # noqa: E501

true_output_C = open(f'{input_path}/coord_swap/output_C.gro', 'r').readlines()
test_output_C = open(f'{input_path}/coord_swap/sim_D/confout.gro', 'r').readlines()
true_output_D = open(f'{input_path}/coord_swap/output_D.gro', 'r').readlines()
test_output_D = open(f'{input_path}/coord_swap/sim_C/confout.gro', 'r').readlines()

os.remove('residue_connect.csv')
os.remove('residue_swap_map.csv')
assert true_output_C == test_output_C
assert true_output_D == test_output_D

def test_process_top(self, params_dict):
import pandas as pd

Expand Down
Loading

0 comments on commit 2fcee10

Please sign in to comment.