-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunSim_in_background
More file actions
564 lines (411 loc) · 19.4 KB
/
runSim_in_background
File metadata and controls
564 lines (411 loc) · 19.4 KB
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
#!/bin/bash
#for filename in $raspa_folder/share/raspa/structures/cif/$COFfile.cif
# ------------------------------------------------------------------#
# runSim
# THIS IS A SCRIPT TO RUN SCREENING WITH RASPA #
# ------------------------------------------------------------------#
# The script requires these folders
#
# > start : containing simulation files
# > parameters: containing parameters for the screening: adsorbate_list and cof_to_be_run
# > dependencies: containing everything needed, but to not be changed, maybe write-protected.
# > log: containing all the log files of the screening
#
# If restarts are needed, you place them in start/RestartInitial
#
#
# runBatchOfSimulations.sh -p [widom/isotherm/water-filling] -r -o -x -c 12
#
# -p flag <arg> REQUIRED (protocol) to pick the right protocol
# -r flag OPTIONAL (RestartInitial) use the restart file. DEFAULT is NO
# -o flag OPTIONAL (overwrite) overwrite the folder / simulation if it already exists. DEFAULT is NO
# -x flag OPTIONAL (exectute) if selected the run file is executed and the simulation starts. DEFAULT is NO
# -h flag OPTIONAL (help) help
# -c flag <arg> OPTIONAL (CPUs) number of CPUs (on w7991)
# -t flag <arg> OPTIONAL (runtime) in hours (on Eddie)
# ------------------------------------------------------------------#
# FOLDERS #
# ------------------------------------------------------------------#
# Retrieve environmental variables
source /home/s2216474/toSiSeMatDatastore/local/PATH # on Eddie
source /localdisk/PATH # on w7991
#raspa_folder=~/RASPA/simulations/ # Just for testing, comment otherwise. ##############################################
folder=$(pwd) # Local folder
cif_databank=$raspa_folder/share/raspa/structures/cif/ # Might vary if you compiled RASPA in a fancy way.
if [ -e ./log ]; then
echo "Log found." # Check if dependencies are there
else
printf "\nERROR: The log folder not found. Are you in the right folder?\n"
pwd
break
fi
log_folder=$folder/log # Log folder
dependencies_folder=$repository_folder/dependencies
# ------------------------------------------------------------------#
# FILENAMES #
# ------------------------------------------------------------------#
cof_list=./parameters/cof_to_be_run.txt #
adsorbate_list=./parameters/adsorbate_list.txt #
input_file=./parameters/input.sh #
log_file=$log_folder/$(date +%F_%T).log # Log file name with the date and time of execution
# ------------------------------------------------------------------#
# FUNCTIONS, CHECKING EXISTANCE AND LOADING INPUT FILES #
# ------------------------------------------------------------------#
# Loading some essential functions.
#
# log print with printf and save it in the log file
#
# checkCPUs $CORES_TO_BE USED $SECONDS check if there are CPUs avaiable
clear # Clean the screen
if [ -e $dependencies_folder/functions_box.sh ]; then # Check if dependencies are there
source $dependencies_folder/functions_box.sh
else
printf "\nERROR: Dependencies not found. Please check $dependencies_folder\n"
exit
fi
log $(date +%c) # Date and time at start for the log.
ls $cif_databank | awk -F'.cif' '{print $1}' | sort > database.txt # This is the database of COFs in RASPA.
if [ -e $input_file ]; then # Check if the list of COFs is there
log $line_break
################################### Force to be UNIX format
source $input_file
log "\n- Files input.sh found and loaded."
else
log $line_break
log "\nERROR File input.sh. You can create it. \n"
exit
fi
if [ -e $adsorbate_list ]; then # Check if the list of COFs is there
log $line_break
log "\n- Reading the adsorbate list:\n\n"
################################### Force to be UNIX format
#more $adsorbate_list;
#more $adsorbate_list >> $log_file
# Lines in common between the database and the input: THE .cif EXISTS
else
log "\nERROR File adsorbate_list not found.\n"
exit
fi
if [ -e $cof_list ]; then # Check if the list of COFs is there
log $line_break
log "\n- Reading the input file (cof_to_be_run.txt)." # sort and remove duplicates
################################### Force to be UNIX format
sort -o $cof_list $cof_list
sort -o $cof_list $cof_list >> $log_file
log $line_break
log "\n- Files NOT found in the database:\n\n"
# Lines only in the input: THE .cif DOES NOT EXIST
comm -13 database.txt $cof_list
comm -13 database.txt $cof_list >> $log_file
log $line_break
log "\n- Files found in the database:\n\n"
# Lines in common between the database and the input: THE .cif EXISTS
comm -12 database.txt $cof_list
comm -12 database.txt $cof_list >> $log_file
log $line_break
else
log "\n- File with COF not found. You can create it doing:"
log "\n ls <CIF-FOLDER>/*.cif > cof_to_be_run.txt"
exit
fi
if [ -e 'start' ]; then # Check if start folder is there, otherwise you create it
log "\n- Folder start exist. This folder supposedly contains force fields files.\n"
ls -l start
ls -l start >> $log_file
else
log "\nPlease move in the folder named 'start' input and forcefield files."
mkdir start
exit
fi
if [ -e './start/RestartInitial' ]; then # Check if RestartInitial folder is there, otherwise you create it
log $line_break
log "\n- Folder RestartInitial exist."
else
mkdir ./start/RestartInitial
log "\nPlace the Restart Files in here."
log $line_break
fi
# ------------------------------------------------------------------#
# FLAGS DECLARATION #
# ------------------------------------------------------------------#
help=no
while getopts p:roxhc:t: flag
do
case "${flag}" in
p) protocol=${OPTARG};; # Pick the protocol
r) RestartInitial='yes';; # Use the restart initial We need a restart!!!!!!
o) overwrite='yes';; # Overwrite the folder
x) execute='yes';; # Execute
h) help='yes';;
c) NumberOfCPUs=${OPTARG};; # Number of CPUs
t) maxtime=${OPTARG};;
esac
done
# ------------------------------------------------------------------#
# CASE TO SET-UP VARIABLES ACCORDING TO THE PROTOCOL SELECTED #
# ------------------------------------------------------------------#
echo $help
if [ $help = 'yes' ] ; then
clear
more $dependencies_folder/help.dat
exit; fi
case $protocol in
'widom')
conditions_list=$folder/parameters/widom.protocol ;
;;
'isotherm')
conditions_list=$folder/parameters/isotherm_concentrations.protocol ;
;;
'hydration')
conditions_list=$folder/parameters/hydration_pressure.protocol ;
;;
'BET')
conditions_list=$folder/parameters/BET_pressure.protocol; Temperature=77;
;;
'water-filling')
conditions_list=$folder/parameters/water-filling.protocol ;
;;
'charges')
conditions_list=$folder/parameters/charges.protocol ;
;;
*)
log "\nERROR No protocol selected.\n" # If none of the procols are recognized, the script interrupts.
exit
;;
esac
log $line_break
#log "\n - Condition file selected looks like this."
#log "\n$conditions_list\n"
more $conditions_list
# --------------------------------------------------#
# PRINT THE MAIN PARAMETER TO AVOID SURPRISES #
# --------------------------------------------------#
log $line_break
log "\nPROTOCOL: $protocol"
log "\nNumber Of Adsorbate Molecules: $NumberOfAdsorbateMolecules" # Initial adsorbate mol
log "\nSwap Probability of Adsorbate: $SwapProbabilityofAdsorbate"
log "\nNumber Of Cycles $NumberOfCycles"
log "\nNumber Of Initialization Cycle: $NumberOfInitializationCycles"
log "\nNumber of Cores: $NumberOfCPUs"
log "\nTemperature: $Temperature"
log "\nPressure: $Pressure"
log "\n"
if [ $overwrite = 'yes' ] ; then
log "\nWARNING: Careful, you might overwrite what is already there."; fi
if [ $RestartInitial = 'yes' ] ; then
log "\nWARNING: Please check, you might not have all the Restart Files in ./start. "; fi
if [ $execute = 'yes' ] ; then
log "\nWARNING: In this way, you are running the simulations. "; fi
log "\n"
log "\nYou run simulations for $(wc -l < $cof_list) structures, $(wc -l < $adsorbate_list) adsorbates and $(wc -l < $conditions_list) conditions each."
log $line_break
log "\n"
#read -p "Press enter to continue. CTRL+C to break. If nothing happens I will wait 50s and then I will proceed." YESorNO # Give the chance to let the user to check and wait before moving forward.
#wait
sleep 2
log "Starting...\n"
sleep 2
# -----------------------------------------------------------#
# NESTED LOOPS OVER CONDITIONS, ADSORBATES, CIF STRUCTURES #
# -----------------------------------------------------------#
# Nested directories are created as follow:
#
# $filename > $adsorbate > $variable > Output,Movies,Restart (run,simulation.input,force_field) > System_0 > (files)
#
# $filename is COFname
# $adsorbate is the elements of $adsorbate_list (e.g. urea_KBFF, charge)
# $variable is the composition in the protocol named 'isotherm' or the name of the protocol in all the others
cd $folder
while read COFname; # Read the names of the COF to be simulated from the file 'cof_to_be_run.txt'
do
filename=$cif_databank$COFname.cif
if [ -e $filename ] ; then #### The .cif file existOther conditions.
#checkCharges $filename # It check if charges are ok.
#checkComposition $filename
#### ANY CHECK ON THE STRUCTURE NEED TO BE DONE HERE #####################
#
# > CHECK CHARGES, PRINT HISTOGRAM, CHECK CHARGE NEUTRALITY, CHECK IF THE CHARGE IS ZERO
# > zeo++
# > COMPOSITION
# > XRD
#
##########################################################################
mkdir -p $COFname # Create a folder with .cif file name.
cd $folder/$COFname # Move into it.
####################################################################################################################
while read adsorbate;
do
mkdir -p $adsorbate
cd $adsorbate
# --------------------------------------------------#
# LOOP OVER CONDITION OF SIMULATIONS #
# --------------------------------------------------#
####################################################################################################################
while read variable;
do
############## CHECK IF THERE IS ANY CPU THAT IS FREE. #########################################################
checkCPUs $NumberOfCPUs $CheckEvery # Hold on if CPUs are busy.
folder_name=$( echo $COFname.$Temperature.$adsorbate.$variable ) # Folder name in ./COFname/ Delimiter here is a PITA
if [ -d $folder_name ] && [ $overwrite = no ] ; then # Prevent overwriting
log '\n> %-40s exists.\tI skip this file.' $folder_name # Print if a folder is already there.
else
log '\n> %-40s Folder created. ' $folder_name # Print if a folder is already there.
# --------------------------------------------------#
# COMPUTE HOW MANY UNIT CELLS ARE REQUIRED #
# --------------------------------------------------#
# Getting angles of unit cells
alpha=$(grep _cell_angle_alpha $filename | awk '{print $2}')
beta=$(grep _cell_angle_beta $filename | awk '{print $2}')
gamma=$(grep _cell_angle_gamma $filename | awk '{print $2}')
# Getting lenght of the cell
a=$(grep _cell_length_a $filename | awk '{print $2}')
b=$(grep _cell_length_b $filename | awk '{print $2}')
c=$(grep _cell_length_c $filename | awk '{print $2}')
# How big the unit cell needs to be
UnitCellA=$(echo " $cutoff*2/$a/s($beta*3.1415926535/180)/s($gamma*3.1415926535/180)+1" | tr -d $'\r' | bc -l )
UnitCellB=$(echo " $cutoff*2/$b/s($alpha*3.1415926535/180)/s($gamma*3.1415926535/180)+1" | tr -d $'\r' | bc -l )
UnitCellC=$(echo " $cutoff*2/$c/s($alpha*3.1415926535/180)/s($beta*3.1415926535/180)+1" | tr -d $'\r' | bc -l )
## Copy the CIF with partial charges in the main folder.
#cp ./charge_equilibration/$COFname/Movies/System_0/Framework_0_initial_1_1_1_P1.cif
mkdir -p $folder_name
cp -r $folder/start/* $folder_name
cd $folder_name
# --------------------------------------------------#
# WRITE THE INPUT FILE FOR RASPA #
# --------------------------------------------------#
#log "Writing simulation input file!"
echo "SimulationType MonteCarlo
NumberOfCycles $NumberOfCycles
NumberOfInitializationCycles $NumberOfInitializationCycles
PrintEvery 1000
RestartFile $RestartInitial
Forcefield Local
UseChargesFromCIFFile yes
Framework 0
FrameworkName $COFname
ShiftUnitCells 0.0 0.0 0.0
UnitCells ${UnitCellA%.*} ${UnitCellB%.*} ${UnitCellC%.*}" > ./simulation.input # It overwrite any simulation file that was there. That's wanted.
if [ $protocol = 'widom' ]; then # Generate the simulation.input for Widom protocol.
echo "ExternalTemperature $Temperature" >> ./simulation.input
echo "component 0 MoleculeName $adsorbate
MoleculeDefinition Local
FugacityCoefficient 1
WidomProbability 1
CreateNumberOfMolecules $NumberOfAdsorbateMolecules" >> ./simulation.input
fi
if [ $protocol = 'isotherm' ]; then # Generate the simulation.input for isotherm protocol.
MolFraction=$variable
echo "ExternalTemperature $Temperature" >> ./simulation.input
echo "ExternalPressure $Pressure
component 0 MoleculeName $adsorbate
MoleculeDefinition Local
FugacityCoefficient 1
MolFraction $MolFraction
TranslationProbability 1
RotationProbability 1
ReinsertionProbability 0.5
SwapProbability $SwapProbabilityofAdsorbate
CreateNumberOfMolecules $NumberOfAdsorbateMolecules" >> ./simulation.input
echo "component 1 MoleculeName SPC-E
MoleculeDefinition Local
FugacityCoefficient 1
MolFraction $(echo "1-$MolFraction" | bc -l)
TranslationProbability 1
RotationProbability 1
ReinsertionProbability 0.5
SwapProbability 1.0
CreateNumberOfMolecules $NumberOfWaterMolecules" >> ./simulation.input
fi
if [ $protocol = 'hydration' ]; then # Generate the simulation.input for isotherm protocol.
Pressure=$variable
echo "ExternalTemperature $Temperature" >> ./simulation.input
echo "ExternalPressure $Pressure
component 0 MoleculeName SPC-E
MoleculeDefinition Local
TranslationProbability 1
RotationProbability 1
ReinsertionProbability 0.5
SwapProbability 0.5
FugacityCoefficient 1
CreateNumberOfMolecules $NumberOfAdsorbateMolecules" >> ./simulation.input
# To update the MolFraction
fi
if [ $protocol = 'BET' ]; then # Generate the simulation.input for isotherm protocol.
Pressure=$variable
echo "ExternalTemperature 77" >> ./simulation.input
echo "ExternalPressure $Pressure
component 0 MoleculeName N2_TRAPPE
MoleculeDefinition ExampleDefinitions
TranslationProbability 1
RotationProbability 1
ReinsertionProbability 0.5
SwapProbability 0.5
CreateNumberOfMolecules $NumberOfAdsorbateMolecules" >> ./simulation.input
# To update the MolFraction
fi
if [ $protocol = 'water-filling' ]; then # Generate the simulation.input for water filling protocol.
echo "ExternalTemperature 77" >> ./simulation.input
echo "component 0 MoleculeName $adsorbate
MoleculeDefinition Local
FugacityCoefficient 1
TranslationProbability 1
RotationProbability 1
ReinsertionProbability 0.5
SwapProbability 0
CreateNumberOfMolecules $NumberOfAdsorbateMolecules" >> ./simulation.input
echo "component 1 MoleculeName SPC-E
MoleculeDefinition Local
FugacityCoefficient 1
MolFraction 1
TranslationProbability 1
RotationProbability 1
ReinsertionProbability 0.5
SwapProbability 1.0
CreateNumberOfMolecules $NumberOfWaterMolecules" >> ./simulation.input
fi
if [ $protocol = 'charges' ]; then # Generate the simulation.input for charge assignment with Randall-Snurr method.
echo "ExternalTemperature 77" >> ./simulation.input
echo "SimulationType MonteCarlo
NumberOfCycles 0
NumberOfInitializationCycles 0
PrintEvery 100
RestartFile no
Forcefield Local
ChargeFromChargeEquilibration yes
ChargeEquilibrationPeriodic yes
ChargeEquilibrationEwald yes
SymmetrizeFrameworkCharges no
Framework 0
FrameworkName $COFname
ShiftUnitCells 0.0 0.0 0.0
UnitCells ${UnitCellA%.*} ${UnitCellB%.*} ${UnitCellC%.*}" > ./simulation.input
fi
if [ $machine = 'Eddie' ]; then # They need to stay out in case you don't submit the job straight away.
# Tailor our run file
sed -i "s/jobname/COF_$folder_name/g" run_Eddie #Make the job on the cluster have a decent name
sed -i "s/#$ -l h_rt=100:00:00/#$ -l h_rt=$(echo $maxtime):00:00/g" run_Eddie #Make the job on the cluster have a decent name
if [ $execute = 'yes' ]; then
#submit job
qsub run_Eddie ## Run RASPA in background only if the -x flag was used.
fi
fi
if [ $machine = 'w7991' ] && [ $execute = 'yes' ] ; then
./run > RASPA_output_file 2>&1 & ## Run RASPA in background only if the -x flag was used.
log " Simulation launched."
chmod -R 777 $folder
fi
cd $folder/$COFname/$adsorbate # Out of the condition folder
fi # End of if condition of overwriting and existance of the .cif file. It need to be here, because we want to check that the condition is not overwritten, not the whole folder.
done < $conditions_list # Repeat again for a different concentration.
cd $folder/$COFname # Out of the adsorbate folder
done < $folder/$adsorbate_list # Loop over the adsorbate
cd $folder # Go Out of the COF folder
else # If the .cif file does not exists / other conditional on the file
log "\n> %-40s .cif file seems to not exists. ##################" $COFname
fi
done < $folder/$cof_list # Loop over COFs, the file to be read is used as a list of names.
sleep 2s
log $line_break
log "\nDone.\n"
date +%c
rm database.txt