/
tma_py3.py
217 lines (175 loc) · 7.04 KB
/
tma_py3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/python
# -*- coding: utf-8 -*-
# TrajectoryMergeAssist v2.1.1
# A python3 based GUI tool that helps in merging two trajectories on Desmond MD
# Copyright (C) 2021 Avimanyu Bandyopadhyay
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import tkinter
import os
from tkinter import filedialog
root = tkinter.Tk()
root.withdraw()
class MergeMDs(tkinter.Tk):
def __init__(self, parent):
tkinter.Tk.__init__(self, parent)
self.parent = parent
self.initialize()
def initialize(self):
self.grid()
button = tkinter.Button(
self,
text='Browse Desmond "-out.cms" file',
command=self.AskDesmondInputFile,
)
button.grid(column=0, row=1)
button2 = tkinter.Button(
self, text="Choose Desmond Trajectory 1", command=self.AskDesmondTrajectory1
)
button2.grid(column=0, row=2)
button3 = tkinter.Button(
self, text="Choose Desmond Trajectory 2", command=self.AskDesmondTrajectory2
)
button3.grid(column=0, row=3)
button4 = tkinter.Button(
self,
text="Merge Desmond Trajectories",
command=self.MergeDesmondTrajectories,
)
button4.grid(column=0, row=4)
button5 = tkinter.Button(
self,
text='Browse GROMACS Trajectory 1 ".xtc" file',
command=self.AskGROMACSTrajectory1,
)
button5.grid(column=1, row=1)
button6 = tkinter.Button(
self,
text='Browse GROMACS Trajectory 1 ".xtc" file',
command=self.AskGROMACSTrajectory2,
)
button6.grid(column=1, row=2)
button7 = tkinter.Button(
self,
text="Merge GROMACS Trajectories",
command=self.MergeGROMACSTrajectories,
)
button7.grid(column=1, row=3)
self.grid_columnconfigure(0, weight=1)
self.resizable(False, False)
self.update()
self.geometry("490x120")
def AskDesmondInputFile(self):
global cms
cms = tkinter.filedialog.askopenfilename(
parent=root, initialdir="pwd", title='Choose Desmond "-out.cms" file'
)
if len(cms) > 0:
print("%s selected" % cms)
def AskDesmondTrajectory1(self):
global in1_trj
in1_trj = tkinter.filedialog.askdirectory(
parent=root, initialdir="pwd", title="Please Select Desmond Trajectory 1"
)
if len(in1_trj) > 0:
print("You chose %s" % in1_trj)
def AskDesmondTrajectory2(self):
global in2_trj
in2_trj = tkinter.filedialog.askdirectory(
parent=root, initialdir="pwd", title="Please Select Desmond Trajectory 2"
)
if len(in2_trj) > 0:
print("You chose %s" % in2_trj)
def MergeDesmondTrajectories(self):
if os.path.exists(os.path.expandvars("$SCHRODINGER")):
print("\t")
os.system("echo You are using Desmond MD via $SCHRODINGER")
print("\t")
else:
print(
"Desmond MD not installed or $SCHRODINGER path not set correctly. Exiting..."
)
exit()
print("-------------------------------------------------------------")
print("Merging both trajectories into one and generating -out.cms...")
print("-------------------------------------------------------------")
# For Desmond Version >= 2018.1 https://www.schrodinger.com/kb/282357
if os.path.exists(os.path.expandvars("$SCHRODINGER/internal/bin/trj_merge.py")):
os.system(
"$SCHRODINGER/run trj_merge.py %s %s %s -o NewMergedTrajectory"
% (cms, in1_trj, in2_trj)
)
os.system("mv NewMergedTrajectory.cms NewMergedTrajectory-out.cms")
else:
# For Desmond Version < 2018.1 https://www.schrodinger.com/kb/90
os.system(
"$SCHRODINGER/run -FROM desmond manipulate_trj.py %s NewMergedTrajectory %s %s"
% (cms, in1_trj, in2_trj)
)
if os.path.exists("NewMergedTrajectory-out.cms"):
print("...Done!")
print(
"Check your current working directory for new merged trajectory and -out.cms file."
)
print("Thank you for using TrajectoryMergeAssist.")
print("\t")
else:
print("Error! New Merged Trajectory not created! Please contact author.")
print("\t")
exit()
def AskGROMACSTrajectory1(self):
global xtc1
xtc1 = tkinter.filedialog.askopenfilename(
parent=root,
initialdir="pwd",
title="Please Select GROMACS Trajectory 1 .xtc file",
)
if len(xtc1) > 0:
print("%s selected" % xtc1)
def AskGROMACSTrajectory2(self):
global xtc2
xtc2 = tkinter.filedialog.askopenfilename(
parent=root,
initialdir="pwd",
title="Please Select GROMACS Trajectory 2 .xtc file",
)
if len(xtc2) > 0:
print("%s selected" % xtc2)
def MergeGROMACSTrajectories(self):
if os.path.exists("/usr/local/gromacs"):
print("You are using GROMACS via /usr/local/gromacs")
elif os.path.exists("/usr/share/gromacs"):
print("You are using GROMACS via /usr/share/gromacs")
else:
print("Default GROMACS installation not found. Exiting.")
exit()
print("---------------------------------------------------------")
print("Merging both trajectories into one and generating .xtc...")
print("---------------------------------------------------------")
# For GROMACS 2019.1 http://manual.gromacs.org/current/onlinehelp/gmx-trjcat.html
os.system("gmx trjcat -f %s %s -o NewMergedTrajectory.xtc" % (xtc1, xtc2))
if os.path.exists("NewMergedTrajectory.xtc"):
print("...Done!")
print(
"Check your current working directory for new merged trajectory (.xtc) file."
)
print("Thank you for using TrajectoryMergeAssist.")
print("\t")
else:
print("Error! New Merged Trajectory not created! Please contact author.")
print("\t")
exit()
if __name__ == "__main__":
app = MergeMDs(None)
app.title(
"TrajectoryMergeAssist v2.1: Merge Molecular Dynamics Extended Trajectories"
)
app.mainloop()