-
Notifications
You must be signed in to change notification settings - Fork 0
/
raspa_simulations.py
172 lines (146 loc) · 4.95 KB
/
raspa_simulations.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
import re
import os
from ase.io import read
from math import cos, radians
import random
import numpy as np
import gcmc_wrapper
workdir = "/home/theoj/project/diffusion/workflow"
cif_file = "MFI-SI.cif"
atoms = read(cif_file)
forcefield="Dubbeldam2007FlexibleIRMOF-1"
forcefield_cutoff=9
output_dir = os.path.join(workdir, "Output", "System_0")
file_list = os.listdir(output_dir)
raspa_log = [item for item in file_list if re.match(r".*\.data", item)][0]
with open(os.path.join(output_dir, raspa_log), "r") as log:
simulation = log.read()
def extract_raspa_output(raspa_output):
final_loading_section = re.findall(
r"Number of molecules:\n=+[^=]*(?=)", raspa_output
)[0]
enthalpy_of_adsorption_section = re.findall(
r"Enthalpy of adsorption:\n={2,}\n(.+?)\n={2,}", raspa_output, re.DOTALL
)[0]
subsection = re.findall(
r"Component \d \[CO2\].*?(?=Component|\Z)", final_loading_section, re.DOTALL
)[0]
adsorbed = float(
re.findall(
r"(?<=Average loading absolute \[mol/kg framework\])\s*\d*\.\d*",
subsection,
)[0]
)
enthalpy_subsection = re.findall(
r"Total enthalpy of adsorption.*?(?=Q=-H|\Z)",
enthalpy_of_adsorption_section,
re.DOTALL,
)[0]
# convertion to kcal per mol
enthalpy_of_adsorption = float(
re.findall(r"(?<=\[K\])\s*-?\d*\.\d*", enthalpy_subsection)[0]
) * 0.239
heat_of_adsorption = -1 * enthalpy_of_adsorption
return adsorbed, heat_of_adsorption
def calculate_unit_cells(forcefield_cutoff, cif_file):
perpendicular_length = [0, 0, 0]
dim = [0, 0, 0]
angle = [0, 0, 0]
with open(cif_file, "r") as file:
dim_match = re.findall("_cell_length_.\s+\d+.\d+", file.read())
with open(cif_file, "r") as file:
angle_match = re.findall("_cell_angle_\S+\s+\d+", file.read())
for i in range(3):
dim[i] = float(re.findall("\d+.\d+", dim_match[i])[0])
angle[i] = float(re.findall("\d+", angle_match[i])[0])
for i in range(3):
perpendicular_length[i] = dim[i] * abs(
cos(radians(angle[i] - 90))
)
unit_cells = [1, 1, 1]
for i in range(3):
while unit_cells[i] < 2 * forcefield_cutoff / perpendicular_length[i]:
unit_cells[i] += 1
return unit_cells
def working_capacity_vacuum_swing(cif_file, calc_charges=True,
rundir='./temp', rewrite_raspa_input=False):
random.seed(4)
np.random.seed(4)
# adsorption conditions
adsorbed = gcmc_wrapper.gcmc_simulation(
cif_file,
sorbates=["CO2"],
sorbates_mol_fraction=[0.15, 0.85],
temperature=298,
pressure=100000, # 1 bar
rundir=rundir,
)
if calc_charges:
gcmc_wrapper.calculate_mepo_qeq_charges(adsorbed)
gcmc_wrapper.run_gcmc_simulation(
adsorbed,
rewrite_raspa_input=rewrite_raspa_input,
)
(
adsorbed_CO2,
heat_of_adsorption_CO2_298,
) = extract_raspa_output(adsorbed.raspa_output, has_N2=True)
# desorption conditions
residual = gcmc_wrapper.gcmc_simulation(
cif_file,
sorbates=["CO2"],
sorbates_mol_fraction=[1],
temperature=363, # 363,
pressure=10000, # 10000 # 0.1 bar
rundir=rundir,
)
if calc_charges:
gcmc_wrapper.calculate_mepo_qeq_charges(residual)
gcmc_wrapper.run_gcmc_simulation(
residual,
rewrite_raspa_input=rewrite_raspa_input,
)
residual_CO2, heat_of_adsorption_CO2_363 = extract_raspa_output(
residual.raspa_output, has_N2=False
)
output = {
"file": str(cif_file),
"working_capacity_vacuum_swing": adsorbed_CO2 - residual_CO2,
"CO2_uptake_P0.15bar_T298K": adsorbed_CO2,
"CO2_uptake_P0.10bar_T363K": residual_CO2,
"CO2_heat_of_adsorption_P0.15bar_T298K": heat_of_adsorption_CO2_298,
"CO2_heat_of_adsorption_P0.10bar_T363K": heat_of_adsorption_CO2_363,
}
return output
def run_or_fail(cif_path):
try:
return working_capacity_vacuum_swing(cif_path)
except Exception as e:
print(e)
return None
unit_cells = calculate_unit_cells(forcefield_cutoff, cif_file)
atoms.info = {
"UnitCells": unit_cells,
"ExternalTemperature": 300.0,
"FrameworkName": "IRMOF-1",
"FlexibleFramework": "no",
}
parameters = {
"SimulationType": "Minimization",
"NumberOfCycles": 1,
"PrintEvery" : 1,
"MaximumNumberOfMinimizationSteps" : 1000,
"Forcefield": forcefield,
"RMSGradientTolerance": 1e-4,
"MaxGradientTolerance": 1e-4,
"Ensemble": "NVT",
"CutOffVDW": forcefield_cutoff,
"CutOffChargeCharge": forcefield_cutoff,
"CutOffChargeBondDipole": forcefield_cutoff,
"CutOffBondDipoleBondDipole": forcefield_cutoff,
"ChargeMethod": "Ewald",
"EwaldPrecision": 1e-6,
"InternalFrameworkLennardJonesInteractions": "yes",
}
print(parameters, atoms.info)
calc = Raspa(parameters=parameters)