Skip to content

Commit a11cdd2

Browse files
authored
Use cell parameters for qe cell geometry (#19)
1 parent 2b54c93 commit a11cdd2

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

web-conexs-api/src/web_conexs_api/jobfilebuilders.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import math
1+
import io
22
import re
33

44
import numpy as np
5-
from pymatgen.core import Molecule
5+
from pymatgen.core import Lattice, Molecule
66

77
from .models.models import (
88
ConductivityType,
@@ -86,7 +86,7 @@ def build_orca_input_file(
8686
jobfile += " OPT "
8787

8888
if orca_simulation.solvent is not None:
89-
jobfile += "CPCM(" + orca_simulation.solvent + ") "
89+
jobfile += " CPCM(" + orca_simulation.solvent.value + ") "
9090

9191
jobfile += "\n"
9292

@@ -158,6 +158,17 @@ def build_qe_inputfile(qe_simulation: QESimulation, structure: CrystalStructure)
158158

159159
n_type = len(element_set) + 1
160160

161+
lattice = Lattice.from_parameters(
162+
a=structure.a,
163+
b=structure.b,
164+
c=structure.c,
165+
alpha=structure.alpha,
166+
beta=structure.beta,
167+
gamma=structure.gamma,
168+
)
169+
170+
matrix = lattice.matrix
171+
161172
jobfile = "&CONTROL \n"
162173
jobfile += " calculation = 'scf'\n"
163174
jobfile += " etot_conv_thr = 1.0000000000d-05\n"
@@ -172,12 +183,7 @@ def build_qe_inputfile(qe_simulation: QESimulation, structure: CrystalStructure)
172183
jobfile += "/ \n\n"
173184

174185
jobfile += "&SYSTEM \n"
175-
jobfile += " A = " + str(structure.a) + "\n"
176-
jobfile += " B = " + str(structure.b) + "\n"
177-
jobfile += " C = " + str(structure.c) + "\n"
178-
jobfile += " cosBC = " + str(math.cos(math.radians(structure.alpha))) + "\n"
179-
jobfile += " cosAC = " + str(math.cos(math.radians(structure.beta))) + "\n"
180-
jobfile += " cosAB = " + str(math.cos(math.radians(structure.gamma))) + "\n"
186+
jobfile += " ibrav = 0\n"
181187

182188
if qe_simulation.conductivity == ConductivityType.metallic:
183189
occupations = "smearing"
@@ -251,6 +257,17 @@ def build_qe_inputfile(qe_simulation: QESimulation, structure: CrystalStructure)
251257
jobfile += "1 1 1 0 0 0\n"
252258
jobfile += "\n\n"
253259

260+
jobfile += "CELL_PARAMETERS {angstrom}\n"
261+
262+
print(np.array2string(matrix))
263+
s = io.BytesIO()
264+
265+
np.savetxt(s, matrix)
266+
267+
jobfile += s.getvalue().decode()
268+
269+
jobfile += "\n"
270+
254271
return (
255272
jobfile,
256273
qe_simulation.absorbing_atom,

web-conexs-api/tests/test_jobfile_builder.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
MolecularStructure,
1313
OrcaCalculation,
1414
OrcaSimulation,
15+
OrcaSolvent,
1516
QEEdge,
1617
QESimulation,
1718
Simulation,
@@ -37,10 +38,14 @@ def test_orca_xas_filebuilder():
3738

3839
jobfile = build_orca_input_file(test_model, test_structure)
3940

40-
print(jobfile)
41-
4241
assert "%tddft" in jobfile
4342

43+
test_model.solvent = OrcaSolvent.Water
44+
45+
jobfile = build_orca_input_file(test_model, test_structure)
46+
47+
assert "CPCM(Water)" in jobfile
48+
4449

4550
def test_orca_opt_filebuilder():
4651
test_simulation = Simulation(n_cores=1)
@@ -89,7 +94,7 @@ def test_qe_filebuilder():
8994
test_model, test_structure
9095
)
9196

92-
assert "cosAB" in jobfile
97+
assert "CELL_PARAMETERS" in jobfile
9398

9499

95100
def test_fdmnes_crystal_filebuilder():

0 commit comments

Comments
 (0)