forked from Floriy/GJB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJob.py
4026 lines (2982 loc) · 133 KB
/
Job.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import subprocess as sub
import time
from shutil import copyfile
import numpy as np
import math
import Utility as ut
import os, sys, re
import glob
#from scipy.interpolate import griddata
#from mpl_toolkits.mplot3d import Axes3D
#import matplotlib.pyplot as plt
from io import StringIO
#***********************************************************#
#***********************************************************#
#********************* PDB Files list **********************#
#***********************************************************#
#***********************************************************#
W_PDB = """
CRYST1 04.000 04.000 04.000 90.00 90.00 90.00 P1 1
ATOM 1 W W X 1 00.000 00.000 00.000 0.00 0.00
END
"""
OCO_PDB = """
CRYST1 10.000 10.000 10.000 90.00 90.00 90.00 P 1 1
ATOM 1 PC OCO X 1 5.000 5.000 7.865 0.00 0.00
ATOM 2 C OCO X 1 5.000 5.000 3.135 0.00 0.00
END
"""
PW_PDB = """
CRYST1 52.237 82.455 48.563 90.00 90.00 90.00 P1 1
ATOM 1 W PW X 1 8.010 77.839 11.290 0.00 0.00
ATOM 2 WP PW X 1 7.810 77.479 12.630 0.00 0.00
ATOM 3 WM PW X 1 9.260 78.329 11.680 0.00 0.00
END
"""
DSPC_PDB = """
CRYST1 125.000 125.000 100.000 90.00 90.00 90.00 P 1 1
ATOM 1 NC3 DSPCX 2 105.980 90.400 72.500 0.00 0.00
ATOM 2 PO4 DSPCX 2 105.630 90.710 69.500 0.00 0.00
ATOM 3 GL1 DSPCX 2 105.780 90.260 66.500 0.00 0.00
ATOM 4 GL2 DSPCX 2 107.160 90.030 66.500 0.00 0.00
ATOM 5 C1A DSPCX 2 106.230 90.050 63.500 0.00 0.00
ATOM 6 C2A DSPCX 2 105.920 90.250 60.500 0.00 0.00
ATOM 7 C3A DSPCX 2 106.390 90.500 57.500 0.00 0.00
ATOM 8 C4A DSPCX 2 106.320 90.710 54.500 0.00 0.00
ATOM 9 C5A DSPCX 2 106.050 90.770 51.500 0.00 0.00
ATOM 10 C1B DSPCX 2 108.660 89.710 63.500 0.00 0.00
ATOM 11 C2B DSPCX 2 108.450 89.500 60.500 0.00 0.00
ATOM 12 C3B DSPCX 2 108.130 88.940 57.500 0.00 0.00
ATOM 13 C4B DSPCX 2 108.740 88.990 54.500 0.00 0.00
ATOM 14 C5B DSPCX 2 108.540 89.120 51.500 0.00 0.00
END
"""
S1PC_PDB = """
CRYST1 125.000 125.000 100.000 90.00 90.00 90.00 P 1 1
ATOM 1 NC3 S1PCX 2 105.980 90.400 72.500 0.00 0.00
ATOM 2 PO4 S1PCX 2 105.630 90.710 69.500 0.00 0.00
ATOM 3 GL1 S1PCX 2 105.780 90.260 66.500 0.00 0.00
ATOM 4 GL2 S1PCX 2 107.160 90.030 66.500 0.00 0.00
ATOM 5 C1A S1PCX 2 106.230 90.050 63.500 0.00 0.00
ATOM 6 C2A S1PCX 2 105.920 90.250 60.500 0.00 0.00
ATOM 7 C3A S1PCX 2 106.390 90.500 57.500 0.00 0.00
ATOM 8 C4A S1PCX 2 106.320 90.710 54.500 0.00 0.00
ATOM 9 C5A S1PCX 2 106.050 90.770 51.500 0.00 0.00
ATOM 10 C1B S1PCX 2 108.660 89.710 63.500 0.00 0.00
ATOM 11 C2B S1PCX 2 108.450 89.500 60.500 0.00 0.00
ATOM 12 C3B S1PCX 2 108.130 88.940 57.500 0.00 0.00
ATOM 13 C4B S1PCX 2 108.740 88.990 54.500 0.00 0.00
ATOM 14 C5B S1PCX 2 108.540 89.120 51.500 0.00 0.00
END
"""
S2PC_PDB = """
CRYST1 125.000 125.000 100.000 90.00 90.00 90.00 P 1 1
ATOM 1 NC3 S2PCX 2 105.980 90.400 72.500 0.00 0.00
ATOM 2 PO4 S2PCX 2 105.630 90.710 69.500 0.00 0.00
ATOM 3 GL1 S2PCX 2 105.780 90.260 66.500 0.00 0.00
ATOM 4 GL2 S2PCX 2 107.160 90.030 66.500 0.00 0.00
ATOM 5 C1A S2PCX 2 106.230 90.050 63.500 0.00 0.00
ATOM 6 C2A S2PCX 2 105.920 90.250 60.500 0.00 0.00
ATOM 7 C3A S2PCX 2 106.390 90.500 57.500 0.00 0.00
ATOM 8 C4A S2PCX 2 106.320 90.710 54.500 0.00 0.00
ATOM 9 C5A S2PCX 2 106.050 90.770 51.500 0.00 0.00
ATOM 10 C1B S2PCX 2 108.660 89.710 63.500 0.00 0.00
ATOM 11 C2B S2PCX 2 108.450 89.500 60.500 0.00 0.00
ATOM 12 C3B S2PCX 2 108.130 88.940 57.500 0.00 0.00
ATOM 13 C4B S2PCX 2 108.740 88.990 54.500 0.00 0.00
ATOM 14 C5B S2PCX 2 108.540 89.120 51.500 0.00 0.00
END
"""
D1PC_PDB = """
CRYST1 125.000 125.000 100.000 90.00 90.00 90.00 P 1 1
ATOM 1 NC3 D1PCX 2 105.980 90.400 72.500 0.00 0.00
ATOM 2 PO4 D1PCX 2 105.630 90.710 69.500 0.00 0.00
ATOM 3 GL1 D1PCX 2 105.780 90.260 66.500 0.00 0.00
ATOM 4 GL2 D1PCX 2 107.160 90.030 66.500 0.00 0.00
ATOM 5 C1A D1PCX 2 106.230 90.050 63.500 0.00 0.00
ATOM 6 C2A D1PCX 2 105.920 90.250 60.500 0.00 0.00
ATOM 7 C3A D1PCX 2 106.390 90.500 57.500 0.00 0.00
ATOM 8 C4A D1PCX 2 106.320 90.710 54.500 0.00 0.00
ATOM 9 C5A D1PCX 2 106.050 90.770 52.500 0.00 0.00
ATOM 10 C1B D1PCX 2 108.660 89.710 63.500 0.00 0.00
ATOM 11 C2B D1PCX 2 108.450 89.500 60.500 0.00 0.00
ATOM 12 C3B D1PCX 2 108.130 88.940 57.500 0.00 0.00
ATOM 13 C4B D1PCX 2 108.740 88.990 54.500 0.00 0.00
ATOM 14 C5B D1PCX 2 108.540 89.120 52.500 0.00 0.00
END
"""
DPPC_PDB = """
TITLE DPPC sim
REMARK THIS IS A SIMULATION BOX
CRYST1 30.000 30.000 30.000 90.00 90.00 90.00 P 1 1
MODEL 1
ATOM 1 NC3 DPPCX 1 13.368 14.653 25.970 1.00 0.00
ATOM 2 PO4 DPPCX 1 14.408 15.182 23.260 1.00 0.00
ATOM 3 GL1 DPPCX 1 13.608 14.862 19.630 1.00 0.00
ATOM 4 GL2 DPPCX 1 16.237 14.812 18.850 1.00 0.00
ATOM 5 C1A DPPCX 1 12.478 14.262 15.780 1.00 0.00
ATOM 6 C2A DPPCX 1 12.977 14.722 12.990 1.00 0.00
ATOM 7 C3A DPPCX 1 12.727 15.462 10.220 1.00 0.00
ATOM 8 C4A DPPCX 1 12.858 15.573 6.780 1.00 0.00
ATOM 9 C1B DPPCX 1 17.738 15.942 16.150 1.00 0.00
ATOM 10 C2B DPPCX 1 17.948 14.312 13.260 1.00 0.00
ATOM 11 C3B DPPCX 1 17.778 15.573 10.290 1.00 0.00
ATOM 12 C4B DPPCX 1 17.878 14.642 6.820 1.00 0.00
TER
ENDMDL
"""
DLPC_PDB = """
CRYST1 30.000 30.000 30.000 90.00 90.00 90.00 P 1 1
ATOM 1 NC3 DLPCX 1 5.560 4.860 23.400 1.00 0.00
ATOM 2 PO4 DLPCX 1 5.220 6.260 20.220 1.00 0.00
ATOM 3 GL1 DLPCX 1 4.840 5.200 16.780 1.00 0.00
ATOM 4 GL2 DLPCX 1 7.930 5.720 16.400 1.00 0.00
ATOM 5 C1A DLPCX 1 4.150 4.880 13.220 1.00 0.00
ATOM 6 C2A DLPCX 1 3.880 5.100 10.250 1.00 0.00
ATOM 7 C3A DLPCX 1 3.950 5.290 6.840 1.00 0.00
ATOM 8 C1B DLPCX 1 9.590 5.700 13.540 1.00 0.00
ATOM 9 C2B DLPCX 1 8.850 6.380 10.430 1.00 0.00
ATOM 10 C3B DLPCX 1 9.110 5.310 6.910 1.00 0.00
END
"""
SU_PDB = """
CRYST1 04.000 04.000 04.000 90.00 90.00 90.00 P1 1
ATOM 1 TEM TEMPS 1 00.000 00.000 00.000 0.00 0.00
END
"""
pdb_file_list = {'W':{'name':'water_single.pdb','content': W_PDB},
'OCO':{'name':'octanol_single.pdb','content': OCO_PDB},
'PW':{'name':'polwater_single.pdb','content': PW_PDB},
'DSPC':{ 'name':'dspc_single.pdb', 'content':DSPC_PDB},
'S1PC':{ 'name':'s1pc_single.pdb', 'content':S1PC_PDB},
'S2PC':{ 'name':'s2pc_single.pdb', 'content':S2PC_PDB},
'D1PC':{ 'name':'d1pc_single.pdb', 'content':D1PC_PDB},
'DPPC':{ 'name':'dppc_single.pdb', 'content':DPPC_PDB},
'DLPC':{ 'name':'dlpc_single.pdb', 'content':DPPC_PDB},
'SU':{ 'name':'su_single.pdb', 'content':SU_PDB}}
#***********************************************************#
#***********************************************************#
#***********************************************************#
class BaseProject(object):
""" Main project class
This class provides the basis for a job. Derived classes will have different fucntions based on base_project type.
"""
def __init__(self, sample, softwares, path_to_default):
try:
#Softwares
self.softwares = softwares
self.path_to_default = path_to_default
self.protocol = sample['PROTOCOL']
self.job_id = sample['JOBID']
self.job_num = sample['JOBNUM']
self.job_seed = sample['SEED']
self.node = sample['NODE']
self.nbnodes = sample['NBNODES']
self.ppn = sample['PPN']
self.mdrun_opt = sample['MDRUN_OPT']
self.sample_molecules = sample['SAMPLE']
self.type = sample['TYPE']
self.geometry = sample['GEOMETRY']
if 'PBCSHIFT' in sample['GEOMETRY'] :
self.pbcshift = float(sample['GEOMETRY']['PBCSHIFT'])
else :
self.pbcshift = 5.0
self.dimensions = {'LX': float(sample['GEOMETRY']['LX']),
'LY': float(sample['GEOMETRY']['LY']),
'LZ': float(sample['GEOMETRY']['LZ'])}
self.bottom_z = 0.0
self.sol_thickness = None
if self.type.startswith('MONO'):
self.sol_thickness = float(sample['GEOMETRY']['SOL_THICKNESS'])
self.lz_vaccum = None
if 'LzVac' in sample['GEOMETRY']:
self.lz_vaccum = float(sample['GEOMETRY']['LzVac'])
self.fillmode = None
if 'FILLMODE' in sample['GEOMETRY']:
self.fillmode = sample['GEOMETRY']['FILLMODE']
if self.fillmode == 'PARTIAL-X':
assert(False),"PARTIAL-X not implemented yet"
if 'MIN' in sample['GEOMETRY']:
self.minsolvent = float(sample['GEOMETRY']['MIN'])
else:
self.minsolvent = 0.0
if 'MAX' in sample['GEOMETRY']:
self.maxsolvent = float(sample['GEOMETRY']['MAX'])
else:
self.maxsolvent = float(self.dimensions['LX'])
if self.fillmode == 'PARTIAL-Y':
assert(False),"PARTIAL-Y not implemented yet"
if 'MIN' in sample['GEOMETRY']:
self.minsolvent = float(sample['GEOMETRY']['MIN'])
else:
self.minsolvent = 0.0
if 'MAX' in sample['GEOMETRY']:
self.maxsolvent = float(sample['GEOMETRY']['MAX'])
else:
self.maxsolvent = float(self.dimensions['LY'])
if self.fillmode == 'PARTIAL-Z':
print("PARTIAL-Z not tested with LIPIDS/DEFO/SU systems ! check bottom_z contraints before use ")
if 'MIN' in sample['GEOMETRY']:
self.minsolvent = float(sample['GEOMETRY']['MIN'])
else:
self.minsolvent = 0.0
if 'MAX' in sample['GEOMETRY']:
self.maxsolvent = float(sample['GEOMETRY']['MAX'])
else:
self.maxsolvent = float(self.dimensions['LZ'])
if self.type.startswith('SOLVENT'):
self.bottom_z = self.minsolvent
self.radius = None
if 'Radius' in sample['GEOMETRY']:
self.radius = sample['GEOMETRY']['Radius']
#defo related
self.defo = None
#su related
self.su = None
self.nb_su = None
self.rugosity = None
# monolayer related
self.mono = None
#wall related
self.wall = None
#thermostat related
self.thermostat = None
if 'DEFO' in sample:
self.defo = sample['DEFO']
self.defo_dict = {'DEFB' : {} }
if 'SU' in sample:
self.su = sample['SU']
if 'RUGOSITY' in sample['SU']:
entries = sample['SU']['RUGOSITY'].split('|')
self.rugosity = {}
for e in entries:
parameter_name = e.split(':')[0]
parameter_value = e.split(':')[1]
if ut.is_number(parameter_value):
self.rugosity.update({parameter_name : float(parameter_value)})
else:
self.rugosity.update({parameter_name : parameter_value})
if 'MONO' in sample:
self.mono = sample['MONO']
if 'WALL' in sample:
self.wall = sample['WALL']
if self.su is None:
self.bottom_z = 3.0
if 'THERMOSTAT' in sample:
self.thermostat = sample['THERMOSTAT']
self.protocol = sample['PROTOCOL']
self.system = None
self.shell = 3.0
except RuntimeError as e:
print(e)
self.lipid_list = ['DSPC','DPPC','DLPC','S1PC','S2PC','D1PC']
self.solvent_list = ['W','OCO','PW']
self.substrate_list = ['SSUP','SSUN','SSna','SSn0']
self.packmol_seed = None
self.packmol_input = None
self.lipid_types = None
self.solvent_types = None
if sample['SEED'] == 'time':
self.packmol_seed = int(time.time())
elif sample['SEED'] == 'jobnum':
self.packmol_seed = sample['JOBNUM'] * 123456789
if self.packmol_seed is not None:
self.packmol_input = """
# Packmol seed was set using {0}
seed {1:d}
tolerance 5.0
nloop0 1000
filetype pdb\n""".format(sample['SEED'], self.packmol_seed)
else:
self.packmol_input = """
# Packmol seed was set using default
nloop0 1000
tolerance 3.0
filetype pdb\n"""
self.packmol_input += """
sidemax 1000000"""
def from_input(self, inputs):
""" Method to create sample from already existing configuration
"""
self.lipid_type = None
self.solvent_type = None
for lipid in self.lipid_list:
if lipid in self.sample_molecules:
self.lipid_type = lipid
if self.lipid_type is not None:
self.lipid_types = [self.lipid_type]
self.solvent_types = []
for sol in self.solvent_list:
if sol in self.sample_molecules:
self.solvent_types.append(sol)
print("Looking for .gro file: {0}".format(inputs['GRO']))
file_found = glob.glob(inputs['GRO'])
assert(file_found), "{0} not found".format(inputs['GRO'])
gro_file = file_found[0]
path = ""
if '/' in gro_file:
path = '/'.join(gro_file.split('/')[:-1])
gro_file = gro_file.split('/')[-1]
print("Using: {0}".format(gro_file) )
self.system = '_'.join(gro_file.split('_')[:-1])
if 'TOP' not in inputs:
top_file = self.system + '.top'
else:
top_file = inputs['TOP']
if 'NDX' not in inputs:
ndx_file = self.system + '.ndx'
else:
ndx_file = inputs['NDX']
if 'TPR' not in inputs:
tpr_file = gro_file.replace('.gro','.tpr')
else:
tpr_file = inputs['TPR']
try:
sub.call( "cp {0} ./{1}.gro".format( '{0}/{1}'.format(path, gro_file), self.system ), shell=True)
sub.call( "cp {0} ./{1}.tpr".format( '{0}/{1}'.format(path, tpr_file), self.system ), shell=True)
sub.call( "cp {0} .".format( '{0}/{1}'.format(path, ndx_file) ), shell=True)
except IOError as e:
print(e)
read_index_cmd = """cat {0} | grep "\[" """.format(ndx_file)
read_index_proc = sub.Popen(read_index_cmd, stdout=sub.PIPE, stderr=sub.PIPE, shell=True)
read_index_out = read_index_proc.stdout.read()
print(read_index_out.splitlines())
nb_index = len(read_index_out.splitlines())
#Retrieving the index
self.nb_index = nb_index
create_su = False
generate_su = False
add_monolayer = False
try:
if self.defo:
sub.call( "cp {0}/defos_topo.itp .".format(path), shell=True)
sub.call( "cp {0}/defo_posres_DEFB_gen.itp .".format(path), shell=True)
if self.su:
su_posres = "{0}/su_posres_gen.itp".format(path)
if 'GEN_SU' in inputs:
generate_su = True
elif os.path.isfile(su_posres):
sub.call( "cp {0}/su_posres_gen.itp .".format(path), shell=True)
else:
create_su = True
if self.mono:
add_monolayer = True
except IOError as e:
print(e)
translate = None
# Get the dimensions of the box from the input gro file
dimensions = str(ut.tail(file_found[0], 1)[0], 'utf-8').replace(repr('\n'),'')
dimensions = dimensions.split()
dimensions = [float(D) for D in dimensions]
if 'TRANS' in inputs:
translate = [float(T)/10. for T in inputs['TRANS'].strip().split()]
translate_cmd = str("printf 'System\\n' | {0} trjconv -f {1}.gro -s {1}.tpr -o {1}.gro -n {1}.ndx -pbc mol "
"-trans {2} {3} {4}").format(self.softwares['GROMACS_LOC'],
self.system,
translate[0], translate[1], translate[2],
)
sub.call(translate_cmd, shell=True)
#Increase box size in each dimension
if 'NEWBOX' in inputs:
increment = [float(N)/10. for N in inputs['NEWBOX'].strip().split()]
newbox = np.add(increment, dimensions)
print("newbox :", newbox)
new_box_cmd = str("printf 'System\\n' | {0} trjconv -f {1}.gro -s {1}.tpr -o {1}.gro -n {1}.ndx -pbc mol "
"-box {2} {3} {4}").format(self.softwares['GROMACS_LOC'],
self.system,
newbox[0], newbox[1], newbox[2])
dimensions = newbox
sub.call(new_box_cmd, shell=True)
if 'THRESHOLD-Z' in inputs and 'THRESHOLD_ATOMS' in inputs: #TO MODIFY
thresholds = float(inputs['THRESHOLD-Z'])/10.
thresholds_atoms = inputs['THRESHOLD_ATOMS'].strip().split()
#[float(T)/10. for T in inputs['THRESHOLD'].strip().split()]
atoms = ""
nb_atoms = 0
modified_topology = {}
serials = []
with open("{0}.gro".format(self.system),'r') as gro_input:
for line in gro_input:
split_line = line.split()
if len(split_line) < 3 or line.startswith('Generated'): continue
# Add the pbc
if len(split_line) == 3:
atoms += line
continue
#Look at the z below the thickness
#x = float(line.split()[-6])
#y = float(line.split()[-5])
z = float(line.split()[-4])
name = line[5:9].strip()
serial = line[0:5].strip()
# Dictionnary to update the topology
if name not in modified_topology:
modified_topology[name] = {'atoms': 0, 'molecules': 0}
if name in thresholds_atoms:
#print("{0} in {1}".format(name, thresholds_atoms))
if z < thresholds:
atoms += line
modified_topology[name]['atoms'] += 1
nb_atoms += 1
if serial not in serials:
serials.append(serial)
modified_topology[name]['molecules'] += 1
else:
atoms += line
modified_topology[name]['atoms'] += 1
nb_atoms += 1
if serial not in serials:
serials.append(serial)
modified_topology[name]['molecules'] += 1
after_threshold_content = "AFTER_THRESHOLD-Z of {2}\n{0}\n{1}".format(nb_atoms, atoms, thresholds)
system = self.system.split('_')[0]
for name in modified_topology:
system += "_{0}{1}".format(modified_topology[name]['molecules'], name)
with open('{0}.gro'.format(system),'w') as output_gro:
output_gro.write(after_threshold_content)
for lipid in self.lipid_list:
if lipid in modified_topology:
self.lipid_type = lipid
if self.lipid_type is not None:
self.lipid_types = [self.lipid_type]
self.solvent_types = []
for sol in self.solvent_list:
if sol in modified_topology:
self.solvent_types.append(sol)
self.sample_molecules = {}
for name in modified_topology:
self.sample_molecules[name] = modified_topology[name]['molecules']
grotopdb_cmd = "{0} editconf -f {1}.gro -o {1}.pdb -c no".format(self.softwares['GROMACS_LOC'], system)
sub.call(grotopdb_cmd, shell=True)
make_ndx_cmd = """printf "q\\n" | {0} make_ndx -f {1}.gro -o {1}.ndx""".format(self.softwares['GROMACS_LOC'], system)
sub.call(make_ndx_cmd, shell=True)
list_of_ndx = None
with open("{0}.ndx".format(system)) as ndx:
content = ndx.read()
regex = re.compile("\[ .*", re.MULTILINE)
list_of_ndx = regex.findall(content)
list_of_ndx = [ndx[1:-1].strip() for ndx in list_of_ndx]
nb_index = len(list_of_ndx)
index_for_bilayer = []
for lipid in self.lipid_list:
if lipid in list_of_ndx:
index_for_bilayer.append(list_of_ndx.index(lipid))
index_for_defo = []
if "DEFB" in list_of_ndx:
index_for_defo.append(list_of_ndx.index("DEFB"))
index_for_substrate = []
for su in self.substrate_list:
if su in list_of_ndx:
index_for_substrate.append(list_of_ndx.index(su))
add_to_ndx = ""
name_new_ndx = ""
if index_for_bilayer:
index_for_bilayer = [str(ndx) for ndx in index_for_bilayer]
add_to_ndx += repr("{0}\n".format(" | ".join(index_for_bilayer)))
name_new_ndx += repr("name {0} bilayer\n".format(nb_index))
nb_index += 1
if index_for_defo:
index_for_defo = [str(ndx) for ndx in index_for_defo]
add_to_ndx += repr("{0}\n".format(" | ".join(index_for_defo)))
name_new_ndx += repr("name {0} defo\n".format(nb_index))
nb_index += 1
if index_for_substrate:
index_for_substrate = [str(ndx) for ndx in index_for_substrate]
add_to_ndx += repr("{0}\n".format(" | ".join(index_for_substrate)))
name_new_ndx += repr("name {0} su\n".format(nb_index))
nb_index += 1
make_index_input = add_to_ndx + name_new_ndx + repr("q\n")
print(make_index_input)
upating_ndx_cmd = """printf {2} | {0} make_ndx -f {1}.gro -n {1} -o {1}.ndx""".format(self.softwares['GROMACS_LOC'], system, make_index_input)
sub.call(upating_ndx_cmd, shell=True)
#name_to_remove = thresholds_atoms + ["System"]
#index_to_remove = []
#for name in name_to_remove:
#for ndx in list_of_ndx:
#if name in ndx:
#index_to_remove.append(list_of_ndx.index(ndx))
#new_index_input = ""
##removing old indexes for atoms we removed
#updating_index = 0
#for index in index_to_remove:
#new_index_input += repr("del {0}\n".format(index-updating_index))
#updating_index += 1
##updating indexes for the modified atoms
#new_index = 0
#for name in thresholds_atoms:
#new_index_input += repr("r {0}\n".format(name))
#new_index += 1
##Retrieving the index
#self.nb_index = len(list_of_ndx) - updating_index + new_index
#group_index = [str(i) for i in range(0, self.nb_index, 1)]
#if not create_su:
#new_index_input += repr("{0}\nname {1} System\n".format(" | ".join(group_index), int(group_index[-1])+1))
#new_index_input += repr("q\n")
#print(new_index_input)
#upating_ndx_cmd = """printf {3} | {0} make_ndx -f {1}.gro -n {2} -o {1}.ndx""".format(self.softwares['GROMACS_LOC'], system,
#self.system, new_index_input)
#sub.call(upating_ndx_cmd, shell=True)
self.system = system
elif 'GEN_SU' in inputs:
pass
else:
#if 'THRESHOLD-Z' not in inputs or 'THRESHOLD_ATOMS' not in inputs:
if 'THRESHOLD-Z' in inputs:
assert('THRESHOLD_ATOMS' in inputs), "You forgot to put THRESHOLD_ATOMS in your Parameters.csv"
if 'THRESHOLD_ATOMS' in inputs:
assert('THRESHOLD-Z' in inputs), "You forgot to put THRESHOLD-Z in your Parameters.csv"
modified_topology = {}
serials = []
with open("{0}.gro".format(self.system),'r') as gro_input:
for line in gro_input:
split_line = line.split()
if len(split_line) < 3 or line.startswith('Generated'): continue
# Add the pbc
if len(split_line) == 3: continue
z = float(line.split()[-4])
name = line[5:9].strip()
serial = line[0:5].strip()
# Dictionnary to update the topology
if name not in modified_topology:
modified_topology[name] = {'atoms': 0, 'molecules': 0}
modified_topology[name]['atoms'] += 1
if serial not in serials:
serials.append(serial)
modified_topology[name]['molecules'] += 1
for lipid in self.lipid_list:
if lipid in modified_topology:
self.lipid_type = lipid
if self.lipid_type is not None:
self.lipid_types = [self.lipid_type]
self.solvent_types = []
for sol in self.solvent_list:
if sol in modified_topology:
self.solvent_types.append(sol)
self.sample_molecules = {}
for name in modified_topology:
self.sample_molecules[name] = modified_topology[name]['molecules']
if create_su:
# pdb file for su
assert(len(self.su['SuType']) <= 4),"The name of the SU should be 4 letters max (Otherwise problem with PDB file format)"
su_type = self.su['SuType'] + (4 - len(self.su['SuType']))*' '
atom_type = None
if self.su['SuType'].startswith('SU'):
atom_type = self.su['SuType'][-2:] + (3 - len(self.su['SuType'][-2:]))*' '
elif self.su['SuType'].startswith('S'):
atom_type = self.su['SuType'][-3:] + (3 - len(self.su['SuType'][-3:]))*' '
#if 'SCALE' in inputs:
#scaleby = inputs['SCALE'].strip().split()
#scalegro_cmd = "{0} editconf -f {1}.gro -o {1}.gro -scale {2} {3} {4}".format(self.softwares['GROMACS_LOC'], self.system,
#scale_by[0], scale_by[1], scale_by[2])
#sub.call(scalegro_cmd, shell=True)
grotopdb_cmd = "{0} editconf -f {1}.gro -o {1}.pdb -c no".format(self.softwares['GROMACS_LOC'], self.system)
sub.call(grotopdb_cmd, shell=True)
#self.nb_su = int( float(self.su['Density']) * dimensions[0] * dimensions[1] * float(self.su['Thickness']) / 10 )
su_atoms = ""
self.nb_su = 0
total_thickness = 0.0
if self.rugosity is not None:
su_gro = open(inputs['SU'],'r').readlines()
read_from = StringIO(''.join(su_gro[2:-1]))
x_gro, y_gro, z_gro = np.loadtxt(read_from, usecols=(3,4,5), unpack=True)
#x_gro, y_gro = zip(*sorted(zip(x_gro, y_gro)))
box_dim = str(ut.tail(inputs['SU'], 1)[0], 'utf-8')
box_dim = box_dim.strip().split()
box_dim = [ float(dim) for dim in box_dim]
su_input = open(inputs['SU'],'r').readlines()
if self.rugosity['type'].startswith('1dsine'):
def sine1D(x, box_x, lx):
to_radian = 2. * math.pi
freq = to_radian * self.rugosity['lx']/10.
height = self.rugosity['z']/10.
thickness = float(self.su['Thickness']) / 10.
result = thickness + height * np.sin(freq*x/box_x)
result[np.where(result < thickness)] = thickness
return result
x_height = sine1D(x_gro, box_dim[0], self.rugosity['lx'])
for x,y,z,t,line in zip(x_gro, y_gro, z_gro, x_height, su_input[2:-1]):
if z <= t:
su_atoms += line
self.nb_su += 1
total_thickness = float(self.su['Thickness']) + self.rugosity['z']
if self.rugosity['type'].startswith('1dbool'):
def sine1D(x, box_x, lx):
to_radian = 2. * math.pi
freq = to_radian * self.rugosity['lx']/10.
height = self.rugosity['z']/10.
thickness = float(self.su['Thickness']) / 10.
result = thickness + height * np.sin(freq*x/box_x)
result[np.where(result > thickness)] = thickness + height
result[np.where(result < thickness)] = thickness
return result
x_height = sine1D(x_gro, box_dim[0], self.rugosity['lx'])
for x,y,z,t,line in zip(x_gro, y_gro, z_gro, x_height, su_input[2:-1]):
if z <= t:
su_atoms += line
self.nb_su += 1
total_thickness = float(self.su['Thickness']) + self.rugosity['z']
#if self.rugosity['type'].startswith('2dbool'):
#def sine1D(x, box_x, lx):
#to_radian = 2. * math.pi
#freq = to_radian * self.rugosity['lx']/10.
#height = self.rugosity['z']/10.
#thickness = float(self.su['Thickness']) / 10.
#result = thickness + height * np.sin(freq*x/box_x)
#result[np.where(result > thickness)] = thickness + height
#result[np.where(result < thickness)] = thickness
#return result
#x_height = sine1D(x_gro, box_dim[0], self.rugosity['lx'])
#for x,y,z,t,line in zip(x_gro, y_gro, z_gro, x_height, su_input[2:-1]):
#if z <= t:
#su_atoms += line
#self.nb_su += 1
#total_thickness = float(self.su['Thickness']) + self.rugosity['z']
else:
with open(inputs['SU'],'r') as su_input:
for line in su_input:
split_line = line.split()
#print(split_line)
if len(split_line) < 3: continue
# Add the pbc
if len(split_line) == 3:
split_line[2] = float(self.su['Thickness'])/10.
su_atoms += " {0} {1} {2}".format(split_line[0], split_line[1], split_line[2])
continue
#Look at the z below the thickness
x = float(line.split()[-6])
y = float(line.split()[-5])
z = float(line.split()[-4])
if (z < (float(self.su['Thickness']) / 10.) ) and (x < dimensions[0]) and (y < dimensions[1]) :
su_atoms += line
self.nb_su += 1
total_thickness = float(self.su['Thickness'])
su_atoms = su_atoms.replace("TEMP", self.su['SuType'])
su_atoms = su_atoms.replace("TEM", atom_type)
substrate_content = "SUBSTRATE\n{0}\n{1}".format(self.nb_su, su_atoms)
system = self.system + "_{0}{1}{2}".format(self.nb_su, self.su['SuType'], self.su['Version'])
with open('substrate.gro','w') as substrate_file:
substrate_file.write(substrate_content)
grotopdb_cmd = "{0} editconf -f substrate.gro -o substrate.pdb -c no".format(self.softwares['GROMACS_LOC'])
sub.call(grotopdb_cmd, shell=True)
shell = 7.0
self.packmol_input += """
avoid_overlap yes
output {0}.pdb
# Input structure
structure {1}.pdb
fixed 0. 0. {2} 0.0 0.0 0.0
end structure
# Substrate
structure substrate.pdb
fixed 0. 0. 0. 0. 0. 0.
end structure
""".format(system, self.system, total_thickness+shell)
#su_pdb_content = pdb_file_list['SU']['content'].replace("TEMP", su_type)
#su_pdb_content = su_pdb_content.replace("TEM", atom_type)
#with open(pdb_file_list['SU']['name'],'w') as su_pdb:
#su_pdb.write(ut.RemoveUnwantedIndent(su_pdb_content))
with open("packmol_{0}.input".format(self.system), 'w') as packmol_file:
packmol_file.write(ut.RemoveUnwantedIndent(self.packmol_input))
packmol_cmd = str("{0} < packmol_{1}.input > packmol_{1}.output "
).format(self.softwares['PACKMOL'], self.system)
sub.call(packmol_cmd, shell=True)
pdbtogro_cmd = "{0} editconf -f {1}.pdb -o {1}.gro -box {2} {3} {4} -c no".format(self.softwares['GROMACS_LOC'], system,
dimensions[0], dimensions[1],
dimensions[2] + (total_thickness + 2*shell)/10)
sub.call(pdbtogro_cmd, shell=True)
group_index = [str(i) for i in range(0, self.nb_index-1, 1)]
make_ndx_input = """ "r {0}\\nname {1} su\\ndel 0\\ndel 0\\n{2}\\nname {3} System\\nq\\n" """.format(self.su['SuType'],
self.nb_index,
" | ".join(group_index),
int(group_index[-1])+1)
add_su_ndx_cmd = """printf {3} | {0} make_ndx -f {1}.gro -n {2} -o {1}.ndx""".format(self.softwares['GROMACS_LOC'], system,
self.system, make_ndx_input)
sub.call(add_su_ndx_cmd, shell=True)
self.system = system
if generate_su:
""" Create a substrate for the given input"""
su_density = float(self.su['Density'])
thickness = float(self.su['Thickness'])
assert(len(self.su['SuType']) <= 4),"The name of the SU should be 4 letters max (Otherwise problem with PDB file format)"
su_type = self.su['SuType'] + (4 - len(self.su['SuType']))*' '
atom_type = None
if self.su['SuType'].startswith('SU'):
atom_type = self.su['SuType'][-2:] + (3 - len(self.su['SuType'][-2:]))*' '
elif self.su['SuType'].startswith('S'):
atom_type = self.su['SuType'][-3:] + (3 - len(self.su['SuType'][-3:]))*' '
self.nb_su = int(su_density * dimensions[0] * dimensions[1] * thickness/10.)
system = "substrate_{0}{1}{2}T{3}A".format(self.nb_su, self.su['SuType'], self.su['Version'], int(thickness))
shell = 1.0
self.packmol_input += """
output {0}.pdb
structure {1}
chain S
number {2:g}
inside box 0. 0. {3} {4} {5} {6}
end structure
""".format(system, pdb_file_list['SU']['name'],
self.nb_su, self.bottom_z + shell,
dimensions[0]*10 - shell, dimensions[1]*10 - shell, thickness - shell)
su_pdb_content = pdb_file_list['SU']['content'].replace("TEMP", su_type)
su_pdb_content = su_pdb_content.replace("TEM", atom_type)
with open(pdb_file_list['SU']['name'],'w') as su_pdb:
su_pdb.write(ut.RemoveUnwantedIndent(su_pdb_content))
with open("packmol_substrate.input".format(self.system), 'w') as packmol_file:
packmol_file.write(ut.RemoveUnwantedIndent(self.packmol_input))
packmol_cmd = str("{0} < packmol_substrate.input > packmol_substrate.output "
).format(self.softwares['PACKMOL'], self.system)
sub.call(packmol_cmd, shell=True)
pdbtogro_cmd = "{0} editconf -f {1}.pdb -o {1}.gro -box {2} {3} {4} -c no".format(self.softwares['GROMACS_LOC'], system,
dimensions[0], dimensions[1], thickness/10. )
sub.call(pdbtogro_cmd, shell=True)
make_ndx_input = """ "r {0}\\nname 3 su\\nq\\n" """.format(self.su['SuType'])
add_su_ndx_cmd = """printf {2} | {0} make_ndx -f {1}.gro -o {1}.ndx""".format(self.softwares['GROMACS_LOC'], system,
make_ndx_input)
sub.call(add_su_ndx_cmd, shell=True)
self.system = system
if add_monolayer:
monolayer_z = None
print("dimension=",dimensions)
print("self.dimension=",self.dimensions)
if 'LzM' in self.mono:
monolayer_z = float(self.mono['LzM'])/10.
print("LzM = ",self.mono['LzM'])
print("monolayer_z = ",monolayer_z)
elif 'THRESHOLD-Z' in inputs:
monolayer_z = thresholds
print("thresholds = ",thresholds)