Skip to content

Commit

Permalink
make normal conjugate gradient available
Browse files Browse the repository at this point in the history
  • Loading branch information
samwaseda committed Jan 21, 2021
1 parent c891995 commit 85de89c
Showing 1 changed file with 36 additions and 44 deletions.
80 changes: 36 additions & 44 deletions pyiron_atomistics/sphinx/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@

class SphinxBase(GenericDFTJob):
"""
Class to setup and run Sphinx simulations.
Class to setup and run SPHInX simulations.
Inherits pyiron_atomistics.atomistics.job.generic.GenericJob. The functions in
these modules are written such that the function names and attributes
are very Pyiron-generic (get_structure(), molecular_dynamics(),
version) but internally handle Sphinx specific input and output.
are very pyiron-generic (get_structure(), molecular_dynamics(),
version) but internally handle SPHInX specific input and output.
Alternatively, because SPHInX inputs are built on a group-based
format, users have the option to set specific groups and parameters
Expand Down Expand Up @@ -162,7 +162,7 @@ def fix_spin_constraint(self, boolean):
@plane_wave_cutoff.setter
def plane_wave_cutoff(self, val):
"""
Function to setup the energy cut-off for the Sphinx job in eV.
Function to setup the energy cut-off for the SPHInX job in eV.
Args:
val (int): energy cut-off in eV
Expand Down Expand Up @@ -297,7 +297,7 @@ def get_scf_group(

def get_structure_group(self, keep_angstrom=False):
"""
create a Sphinx Group object based on self.structure
create a SPHInX Group object based on self.structure
Args:
keep_angstrom (bool): Store distances in Angstroms or Bohr
Expand Down Expand Up @@ -358,7 +358,7 @@ def get_structure_group(self, keep_angstrom=False):

def load_default_input(self):
"""
Set defaults for generic parameters and create sphinx input groups.
Set defaults for generic parameters and create SPHInX input groups.
"""

sph = self.input.create_group('sphinx')
Expand All @@ -385,6 +385,7 @@ def load_default_input(self):
self.input.spinMixing = 1.0
self.input.CheckOverlap = True
self.input.THREADS = 1
self.input.use_on_the_fly_cg_optimization = True

def load_structure_group(self, keep_angstrom=False):
"""
Expand Down Expand Up @@ -451,34 +452,30 @@ def load_main_group(self):
)
)
if "Istep" in self.input:
self.input.sphinx.main["ricQN"] = Group(table_name = "input")
self.input.sphinx.main["ricQN"]["maxSteps"] = str(self.input["Istep"])
optimizer = 'linQN'
if self.input.use_on_the_fly_cg_optimization:
optimizer = 'ricQN'
self.input.sphinx.main[optimizer] = Group(table_name = "input")
self.input.sphinx.main[optimizer]["maxSteps"] = str(self.input["Istep"])
if "dE" in self.input and "dF" in self.input:
self.input["dE"] = 1e-3
if "dE" in self.input:
self.input.sphinx.main["ricQN"]["dEnergy"] = str(
self.input.sphinx.main[optimizer]["dEnergy"] = str(
self.input["dE"] / HARTREE_TO_EV
)
if "dF" in self.input:
self.input.sphinx.main["ricQN"]["dF"] = str(
self.input.sphinx.main[optimizer]["dF"] = str(
self.input["dF"] / HARTREE_OVER_BOHR_TO_EV_OVER_ANGSTROM
)
self.input.sphinx.main.ricQN.create_group("bornOppenheimer")
self.input.sphinx.main.ricQN.bornOppenheimer["scfDiag"] = \
self.get_scf_group()
self.input.sphinx.main[optimizer].create_group("bornOppenheimer")
self.input.sphinx.main[optimizer]['bornOppenheimer']["scfDiag"] = self.get_scf_group()
else:
scf = self.input.sphinx.main.get("scfDiag", create = True)
if self._generic_input["restart_for_band_structure"]:
scf.append(
self.get_scf_group(keepRhoFixed=True)
)
scf.append(self.get_scf_group(keepRhoFixed=True))
else:
scf.append(self.get_scf_group())
if self.executable.version is not None:
# vers_num = [
# int(vv)
# for vv in self.executable.version.split("_")[0].split(".")
# ]
if self.get_version_float() > 2.5:
self.input.sphinx.main.create_group("evalForces")["file"] = \
'"relaxHist.sx"'
Expand Down Expand Up @@ -575,7 +572,7 @@ def load_guess_group(self, update_spins=True):
for spin in self.structure.get_initial_magnetic_moments()
]
):
raise ValueError("Sphinx only supports collinear spins.")
raise ValueError("SPHInX only supports collinear spins.")
else:
rho = self.input.sphinx.initialGuess.rho
rho.get("atomicSpin", create = True)
Expand Down Expand Up @@ -606,7 +603,7 @@ def calc_static(
"""
Setup the hamiltonian to perform a static SCF run.
Loads defaults for all Sphinx input groups, including a static
Loads defaults for all SPHInX input groups, including a static
main Group.
Args:
Expand Down Expand Up @@ -652,7 +649,7 @@ def calc_minimize(
ionic_energy_tolerance as a limit for fluctuations in energy or the
ionic_force_tolerance.
Loads defaults for all Sphinx input groups, including a
Loads defaults for all SPHInX input groups, including a
ricQN-based main Group.
Args:
Expand Down Expand Up @@ -747,11 +744,9 @@ def restart_from_charge_density(
Args:
job_name (str/None): Job name
job_type (str/None): Job type. If not specified a Sphinx
job type is assumed (actually this is
all that's currently supported)
band_structure_calc (bool): has to be True for band
structure calculations.
job_type (str/None): Job type. If not specified a SPHInX job type is assumed (actually
this is all that's currently supported)
band_structure_calc (bool): has to be True for band structure calculations.
Returns:
pyiron_atomistics.sphinx.sphinx.sphinx: new job instance
Expand All @@ -777,9 +772,8 @@ def restart_from_wave_functions(
Args:
job_name (str): Job name
job_type (str): Job type. If not specified a Sphinx
job type is assumed (actually this is
all that's currently supported.)
job_type (str): Job type. If not specified a SPHInX job type is assumed (actually
this is all that's currently supported.)
Returns:
pyiron_atomistics.sphinx.sphinx.sphinx: new job instance
Expand Down Expand Up @@ -1089,7 +1083,7 @@ def _set_kpoints(
path_name=None,
):
"""
Function to setup the k-points for the Sphinx job
Function to setup the k-points for the SPHInX job
Args:
reciprocal (bool): Tells if the supplied values are in
Expand Down Expand Up @@ -1256,7 +1250,7 @@ def list_potentials(self):

def write_input(self):
"""
Generate all the required input files for the Sphinx job.
Generate all the required input files for the SPHInX job.
Creates:
structure.sx: structure associated w/ job
Expand Down Expand Up @@ -1410,18 +1404,16 @@ def collect_logfiles(self):

def collect_warnings(self):
"""
Collects warnings from the Sphinx run
Collects warnings from the SPHInX run
"""
# TODO: implement for Sphinx
self._logger.info("collect_warnings() is not yet \
implemented for Sphinx")
implemented for SPHInX")

def collect_errors(self):
"""
Collects errors from the Sphinx run
Collects errors from the SPHInX run
"""
# TODO: implement for Sphinx
self._logger.info("collect_errors() is not yet implemented for Sphinx")
self._logger.info("collect_errors() is not yet implemented for SPHInX")

def get_n_ir_reciprocal_points(
self, is_time_reversal=True, symprec=1e-5, ignore_magmoms=False
Expand Down Expand Up @@ -1658,8 +1650,8 @@ def check_vasp_potentials():

class InputWriter(object):
"""
The Sphinx Input writer is called to write the
Sphinx specific input files.
The SPHInX Input writer is called to write the
SPHInX specific input files.
"""

def __init__(self):
Expand Down Expand Up @@ -1797,7 +1789,7 @@ def write_spin_constraints(
for spin in self.structure.get_initial_magnetic_moments()
]):
raise ValueError(
"Sphinx only supports collinear spins at the moment."
"SPHInX only supports collinear spins at the moment."
)
else:
for spin, value in zip(
Expand Down Expand Up @@ -1890,7 +1882,7 @@ def format_value(v):

class Output(object):
"""
Handles the output from a Sphinx simulation.
Handles the output from a SPHInX simulation.
"""

def __init__(self, job):
Expand Down Expand Up @@ -2330,7 +2322,7 @@ def _get_electronic_structure_object(self):

def collect(self, directory=os.getcwd()):
"""
The collect function, collects all the output from a Sphinx simulation.
The collect function, collects all the output from a SPHInX simulation.
Args:
directory (str): the directory to collect the output from.
Expand Down

0 comments on commit 85de89c

Please sign in to comment.