-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_maestro_scripts.py
301 lines (227 loc) · 9.94 KB
/
my_maestro_scripts.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
"""My Scripts for Schrodinger Maestro Usage
Prefer to using syntax `from SCRIPTS import *`, then all customized functions
will be starting with `myfunc_*`
Care:
1) atom's `index' starts from 1
-> `st.molecule' starts from 1, `st.atom' starts from 1
2) `[a for a in st.atom] != [a for m in st.molecule for a in m]' (important!!)
3) by test, `maestro.project_table_get().included_rows' returns reversed
order of entries, and the operation order matters. It is different
with `selected_rows', which is sorted by row number.
"""
from schrodinger.maestro import maestro
FEATURES = [
'version 0.1.0 : My Schrodinger Scripts, Oct 17th, 2022',
'version 0.2.0 : add `title`s functions',
'version 0.3.0 : add selections for workspace',
'version 0.4.0 : add included functions for workspace',
'version 0.5.0 : make sure properties are copied when getting structures',
'version 0.6.0 : add more funcs and make their names more clear',
'version 0.7.0 : add correspondent `included` functions',
'version 0.8.0 : add `molecule` methods; more workspace specific',
]
VERSION = FEATURES[-1].split(':')[0].replace('version',' ').strip()
__version__ = VERSION
__all__ = [
'myfunc_get_selected_rows',
'myfunc_get_included_rows',
'myfunc_get_selected_titles',
'myfunc_get_included_titles',
'myfunc_get_selected_structures',
'myfunc_get_included_structures',
'myfunc_get_selected_molecules',
'myfunc_get_included_molecules',
'myfunc_get_selected_atoms_separated_by_molecule',
'myfunc_get_included_atoms_separated_by_molecule',
'myfunc_get_selected_atoms_separated_by_entry',
'myfunc_get_included_atoms_separated_by_entry',
'myfunc_get_selected_entry_ids',
'myfunc_get_included_entry_ids',
'myfunc_get_selected_resnames_lists',
'myfunc_get_included_resnames_lists',
'myfunc_get_selected_resnames_sets',
'myfunc_get_included_resnames_sets',
'myfunc_get_selected_resnums',
'myfunc_get_included_resnums',
'myfunc_get_selected_atoms_charges_separated_by_molecule',
'myfunc_get_included_atoms_charges_separated_by_molecule',
'myfunc_get_selected_atoms_charges_separated_by_entry',
'myfunc_get_included_atoms_charges_separated_by_entry',
'myfunc_ws_get_chosen_atoms_indexes',
'myfunc_ws_get_chosen_atoms_indexes_detail',
'myfunc_ws_get_chosen_atoms',
'myfunc_ws_get_chosen_atoms_center_and_size',
]
def _get_rows(included=False):
"""1D: List[row, row, ...]"""
pt = maestro.project_table_get()
if included:
rows = [i for i in pt.included_rows][-1::-1] # important!
print(f'Note: number of included entries: {len(rows)}')
else:
rows = [i for i in pt.selected_rows]
print(f'Note: number of selected entries: {len(rows)}')
info = [','.join([r.title,r.entry_id]) for r in rows]
info = [s.replace('"','').replace("'",'') for s in info]
info = '; '.join(['({:})'.format(s) for s in info])
print(f'Note: -> key-pairs: (title,entry_id): {info}')
return rows
def myfunc_get_selected_rows():
return _get_rows()
def myfunc_get_included_rows():
return _get_rows(included=True)
def myfunc_get_selected_titles():
"""1D: List[str, str, ...]"""
rows = myfunc_get_selected_rows()
return [i.title for i in rows]
def myfunc_get_included_titles():
"""1D: List[str, str, ...]"""
rows = myfunc_get_included_rows()
return [i.title for i in rows]
def myfunc_get_selected_structures():
"""1D: List[structure, structure, ...]"""
rows = myfunc_get_selected_rows()
#return [i.structure for i in rows] # deprecated, properties are not copied!
return [i.getStructure() for i in rows]
def myfunc_get_included_structures():
"""1D: List[structure, structure, ...]"""
rows = myfunc_get_included_rows()
return [i.getStructure() for i in rows]
def myfunc_get_selected_molecules():
sts = myfunc_get_selected_structures()
mols = [[m for m in s.molecule] for s in sts]
print(f'Note: number of total molecules: {sum([s.mol_total for s in sts])}')
return mols
def myfunc_get_included_molecules():
sts = myfunc_get_included_structures()
mols = [[m for m in s.molecule] for s in sts]
print(f'Note: number of total molecules: {sum([s.mol_total for s in sts])}')
return mols
def _get_atoms_separated_by_molecule(included=False):
"""3D: List[[[atom, atom, ...], [atom, atom, ...], ...], ...]"""
if included:
sts = myfunc_get_included_structures()
else:
sts = myfunc_get_selected_structures()
atoms = [[[a for a in m.atom] for m in s.molecule] for s in sts]
print(f'Note: number of total molecules: {sum([s.mol_total for s in sts])}')
print(f'Note: number of total atoms: {sum([s.atom_total for s in sts])}')
return atoms
def myfunc_get_selected_atoms_separated_by_molecule():
return _get_atoms_separated_by_molecule()
def myfunc_get_included_atoms_separated_by_molecule():
return _get_atoms_separated_by_molecule(included=True)
def _get_atoms_separated_by_entry(included=False):
"""2D: List[[atom, atom, ...], ...]"""
if included:
sts = myfunc_get_included_structures()
else:
sts = myfunc_get_selected_structures()
atoms = [[a for a in s.atom] for s in sts]
total = sum([len(s) for s in atoms])
print(f'Note: number of total atoms: {total}')
return atoms
def myfunc_get_selected_atoms_separated_by_entry():
return _get_atoms_separated_by_entry()
def myfunc_get_included_atoms_separated_by_entry():
return _get_atoms_separated_by_entry(included=True)
def myfunc_get_selected_entry_ids():
"""1D: List[str, str, ...]"""
rows = myfunc_get_selected_rows()
ids = [i.entry_id for i in rows]
return ids
def myfunc_get_included_entry_ids():
"""1D: List[str, str, ...]"""
rows = myfunc_get_included_rows()
ids = [i.entry_id for i in rows]
return ids
def myfunc_get_selected_resnames_lists():
"""1D: List[str, str, ...]"""
sts = myfunc_get_selected_structures()
resnames = [[k.pdbres for j in i.molecule for k in j.residue] for i in sts]
print(f'Note: number of total selected residues: {sum([len(i) for i in resnames])}')
return resnames
def myfunc_get_included_resnames_lists():
"""1D: List[str, str, ...]"""
sts = myfunc_get_included_structures()
resnames = [[k.pdbres for j in i.molecule for k in j.residue] for i in sts]
print(f'Note: number of total included residues: {sum([len(i) for i in resnames])}')
return resnames
def myfunc_get_selected_resnames_sets():
"""1D: List[str, str, ...]"""
resnames = myfunc_get_selected_resnames_lists()
return [list(set(i)) for i in resnames]
def myfunc_get_included_resnames_sets():
"""1D: List[str, str, ...]"""
resnames = myfunc_get_included_resnames_lists()
return [list(set(i)) for i in resnames]
def myfunc_get_selected_resnums():
"""1D: List[int, int, ...]"""
sts = myfunc_get_selected_structures()
resnums = [[k.resnum for j in i.molecule for k in j.residue] for i in sts]
print(f'Note: number of total selected residues: {sum([len(i) for i in resnums])}')
return resnums
def myfunc_get_included_resnums():
"""1D: List[int, int, ...]"""
sts = myfunc_get_included_structures()
resnums = [[k.resnum for j in i.molecule for k in j.residue] for i in sts]
print(f'Note: number of total included residues: {sum([len(i) for i in resnums])}')
return resnums
def myfunc_get_selected_atoms_charges_separated_by_molecule():
"""3D: List[[[float, float, ...], [float, float, ...], ...], ...]"""
full = myfunc_get_selected_atoms_separated_by_molecule()
charges = [[[a.partial_charge for a in m] for m in s] for s in full]
return charges
def myfunc_get_included_atoms_charges_separated_by_molecule():
"""3D: List[[[float, float, ...], [float, float, ...], ...], ...]"""
full = myfunc_get_included_atoms_separated_by_molecule()
charges = [[[a.partial_charge for a in m] for m in s] for s in full]
return charges
def myfunc_get_selected_atoms_charges_separated_by_entry():
"""2D: List[[float, float, ...], ...]"""
full = myfunc_get_selected_atoms_separated_by_entry()
charges = [[a.partial_charge for a in m] for m in full]
return charges
def myfunc_get_included_atoms_charges_separated_by_entry():
"""2D: List[[float, float, ...], ...]"""
full = myfunc_get_included_atoms_separated_by_entry()
charges = [[a.partial_charge for a in m] for m in full]
return charges
def myfunc_ws_get_chosen_atoms_indexes():
"""1D: List[int, int, ...]"""
aids = maestro.selected_atoms_get()
print(f'Note: workspace: number of chosen atoms: {len(aids)}')
return [i-1 for i in aids]
def myfunc_ws_get_chosen_atoms():
"""2D: List[[atom, atom, ...], ...]"""
atoms = myfunc_get_included_atoms_separated_by_entry()
aids = myfunc_ws_get_chosen_atoms_indexes()
full = [a for st in atoms for a in st]
return [full[i] for i in aids]
def myfunc_ws_get_chosen_atoms_indexes_detail():
"""1D: List[(eid,mid,aid), (eid,mid,aid), ...]"""
atoms = myfunc_ws_get_chosen_atoms()
return [(a.entry_id,a.molecule_number_by_entry-1,a.index-1) for a in atoms]
def _calc_center_and_size(crds):
# codes may be redundant, but efficient
if not crds: return [(0.0,0.0,0.0), (0.0,0.0,0.0)]
xsum = ysum = zsum = 0.0
xmin = ymin = zmin = 1000000000000000000.
xmax = ymax = zmax = -1000000000000000000.
for r in crds:
xsum += r[0]
ysum += r[1]
zsum += r[2]
xmin = min(xmin,r[0])
ymin = min(ymin,r[1])
zmin = min(zmin,r[2])
xmax = max(xmax,r[0])
ymax = max(ymax,r[1])
zmax = max(zmax,r[2])
n = len(crds)
return [(xsum/n,ysum/n,zsum/n), (xmax-xmin,ymax-ymin,zmax-zmin)]
def myfunc_ws_get_chosen_atoms_center_and_size():
"""2D: List[ CenterCoord(x,y,z), BoxSize(xlen,ylen,zlen) ]"""
atoms = myfunc_ws_get_chosen_atoms()
crds = [a.xyz for a in atoms]
return _calc_center_and_size(crds)