Skip to content

Commit

Permalink
Merge pull request #1277 from pyiron/spx_simplify_input
Browse files Browse the repository at this point in the history
[minor] Simplify SPHInX input
  • Loading branch information
samwaseda authored Jan 2, 2024
2 parents 1f1abfa + f698081 commit 9a882d2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 64 deletions.
59 changes: 3 additions & 56 deletions pyiron_atomistics/sphinx/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,8 @@ def get_scf_group(
]
else:
scf_group.create_group("preconditioner")["type"] = "KERKER"
scf_group.preconditioner.set_parameter(
"scaling", self.input["rhoResidualScaling"]
)
scf_group.preconditioner.set_parameter(
"spinScaling", self.input["spinResidualScaling"]
)
scf_group.preconditioner["scaling"] = self.input["rhoResidualScaling"]
scf_group.preconditioner["spinScaling"] = self.input["spinResidualScaling"]
scf_group.create_group(algorithm)
if "maxStepsCCG" in self.input:
scf_group[algorithm]["maxStepsCCG"] = self.input["maxStepsCCG"]
Expand Down Expand Up @@ -2051,62 +2047,13 @@ class Group(DataContainer):
expected by the given DFT code in its input files.
"""

def set(self, name, content):
self[name] = content

def set_group(self, name, content=None):
"""
Set a new group in SPHInX input.
Args:
name (str): name of the group
content: content to append
This creates an input group of the type `name { content }`.
"""
if content is None:
self.create_group(name)
else:
self.set(name, content)

def set_flag(self, flag, val=True):
"""
Set a new flag in SPHInX input.
Args:
flag (str): name of the flag
val (bool): boolean value
This creates an input flag of the type `name = val`.
"""
self.set(flag, val)

def set_parameter(self, parameter, val):
"""
Set a new parameter in SPHInX input.
Args:
parameter (str): name of the flag
val (float): parameter value
This creates an input parameter of the type `parameter = val`.
"""
self.set(parameter, val)

def remove(self, name):
if name in self.keys():
del self[name]

def to_sphinx(self, content="__self__", indent=0):
if content == "__self__":
content = self

def format_value(v):
if isinstance(v, bool):
if v:
return ";"
else:
return " = false;"
return f" = {v};".lower()
elif isinstance(v, Group):
if len(v) == 0:
return " {}"
Expand Down
2 changes: 1 addition & 1 deletion pyiron_atomistics/sphinx/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def load_main_group(self):
]
)
self.input.sphinx.main.extControl = Group()
self.input.sphinx.main.extControl.set_group("bornOppenheimer")
self.input.sphinx.main.extControl.create_group("bornOppenheimer")
self.input.sphinx.main.extControl.bornOppenheimer = commands
else:
super(SphinxInteractive, self).load_main_group()
Expand Down
14 changes: 7 additions & 7 deletions tests/sphinx/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_write_input(self):
"\t\tatom {\n",
'\t\t\tlabel = "spin_0.5";\n',
"\t\t\tcoords = [0.0, 0.0, 0.0];\n",
"\t\t\tmovable;\n",
"\t\t\tmovable = true;\n",
"\t\t}\n",
"\t\tatom {\n",
'\t\t\tlabel = "spin_0.5";\n',
Expand All @@ -172,25 +172,25 @@ def test_write_input(self):
"\tkPoint {\n",
"\t\tcoords = [0.5, 0.5, 0.5];\n",
"\t\tweight = 1;\n",
"\t\trelative;\n",
"\t\trelative = true;\n",
"\t}\n",
"\tfolding = [4, 4, 4];\n",
"\tsaveMemory;\n",
"\tsaveMemory = true;\n",
"}\n",
"PAWHamiltonian {\n",
"\tnEmptyStates = 6;\n",
"\tekt = 0.2;\n",
"\tMethfesselPaxton = 1;\n",
"\txc = PBE;\n",
"\tspinPolarized;\n",
"\tspinPolarized = true;\n",
"}\n",
"initialGuess {\n",
"\twaves {\n",
"\t\tpawBasis;\n",
"\t\tpawBasis = true;\n",
"\t\tlcao {}\n",
"\t}\n",
"\trho {\n",
"\t\tatomicOrbitals;\n",
"\t\tatomicOrbitals = true;\n",
"\t\tatomicSpin {\n",
'\t\t\tlabel = "spin_0.5";\n',
"\t\t\tspin = 0.5;\n",
Expand Down Expand Up @@ -578,7 +578,7 @@ def test_write_structure(self):
"\tatom {\n",
'\t\tlabel = "spin_0.5";\n',
"\t\tcoords = [0.0, 0.0, 0.0];\n",
"\t\tmovable;\n",
"\t\tmovable = true;\n",
"\t}\n",
"\tatom {\n",
'\t\tlabel = "spin_0.5";\n',
Expand Down

0 comments on commit 9a882d2

Please sign in to comment.