Skip to content

Commit

Permalink
Remove aiida-aimall version of aiida-gaussian
Browse files Browse the repository at this point in the history
  • Loading branch information
kmlefran committed Jul 24, 2024
1 parent d3e5b03 commit 0a3ae01
Show file tree
Hide file tree
Showing 19 changed files with 1,807 additions and 691 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ dependencies = [
"cclib @ git+https://github.com/cclib/cclib",
"multiprocess",
"subproptools",
"pymatgen",
"aiida-shell"
"aiida-gaussian",
"pymatgen==2023.12.18",
"aiida-shell",
]

[project.urls]
Expand Down
273 changes: 3 additions & 270 deletions src/aiida_aimall/calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,10 @@
entry point
"""
from aiida.common import CalcInfo, CodeInfo, datastructures
from aiida.engine import CalcJob, ExitCode
from aiida.orm import (
Dict,
Float,
Int,
List,
RemoteData,
SinglefileData,
Str,
StructureData,
)
from aiida.common import datastructures
from aiida.engine import CalcJob
from aiida.orm import Dict, Int, List, SinglefileData
from aiida.plugins import DataFactory
from pymatgen.io.gaussian import GaussianInput # pylint: disable=import-error

AimqbParameters = DataFactory("aimall.aimqb")

Expand Down Expand Up @@ -155,260 +145,3 @@ def prepare_for_submission(self, folder):
]

return calcinfo


class GaussianWFXCalculation(CalcJob):
"""AiiDA calculation plugin wrapping Gaussian. Adapted from aiida-gaussian
https://github.com/nanotech-empa/aiida-gaussian, Copyright (c) 2020 Kristjan Eimre.
Additions made to enable providing molecule input as orm.Str,
and wfx files are retrieved by default. We further define another input wfxgroup in which you can provide an
optional group to store the wfx file in and fragment_label as an optional extra to add on the output.
Args:
structure: StructureData for molecule to be run. Do not provide structure AND structure_str, but provide
at least one
structure_str: Str for molecule to be run. e.g. orm.Str(H 0.0 0.0 0.0\n H -1.0 0.0 0.0)
Do not provide structure AND structure_str, but provide at least one
wfxgroup: Str of a group to add the .wfx files to
parameters: required: Dict of Gaussian parameters, same as from aiida-gaussian. Note that the options provided should
generate a wfx file. See Example
settings: optional, additional input parameters
fragment_label: Str, optional: an extra to add to the wfx file node. Involved in the controllers,
which check extras
parent_calc_folder: RemoteData, optional: the folder of a completed gaussian calculation
Example:
::
builder = GaussianCalculation.get_builder()
builder.structure_str = orm.Str("H 0.0 0.0 0.0 -1.0 0.0 0.0") # needs newline but docs doesn't like
builder.parameters = orm.Dict(dict={
'link0_parameters': {
'%chk':'aiida.chk',
"%mem": "3200MB", # Currently set to use 8000 MB in .sh files
"%nprocshared": 4,
},
'functional':'wb97xd',
'basis_set':'aug-cc-pvtz',
'charge': 0,
'multiplicity': 1,
'route_parameters': {'opt': None, 'Output':'WFX'},
"input_parameters": {"output.wfx": None},
})
builder.code = orm.load_code("g16@localhost")
builder.metadata.options.resources = {"num_machines": 1, "tot_num_mpiprocs": 4}
builder.metadata.options.max_memory_kb = int(6400 * 1.25) * 1024
builder.metadata.options.max_wallclock_seconds = 604800
submit(builder)
"""

# Defaults
INPUT_FILE = "aiida.inp"
OUTPUT_FILE = "aiida.out"
PARENT_FOLDER_NAME = "parent_calc"
# can override in metadata
DEFAULT_PARSER = "aimall.gaussianwfx"

@classmethod
def define(cls, spec):
super().define(spec)

# Input parameters
spec.input(
"structure",
valid_type=StructureData,
required=False,
help="Input structure; will be converted to pymatgen object",
)
spec.input(
"wfxgroup",
valid_type=Str,
required=False,
help="Group label that output wfx will be a member of",
)
spec.input("structure_str", valid_type=Str, required=False)
spec.input(
"parameters", valid_type=Dict, required=True, help="Input parameters"
)
spec.input(
"settings",
valid_type=Dict,
required=False,
help="additional input parameters",
)
spec.input(
"fragment_label", valid_type=Str, required=False, help="smiles of fragment"
)
spec.input(
"parent_calc_folder",
valid_type=RemoteData,
required=False,
help="the folder of a completed gaussian calculation",
)

# Turn mpi off by default
spec.input("metadata.options.withmpi", valid_type=bool, default=False)

spec.input( # update parser here
"metadata.options.parser_name",
valid_type=str,
default=cls.DEFAULT_PARSER,
non_db=True,
)

# Outputs
spec.output(
"output_parameters",
valid_type=Dict,
required=True,
help="The result parameters of the calculation",
)
spec.output(
"output_structure",
valid_type=StructureData,
required=False,
help="Final optimized structure, if available",
)
spec.output(
"energy_ev",
valid_type=Float,
required=False,
help="Final energy in electronvolts",
)
spec.output(
"wfx",
valid_type=SinglefileData,
required=False,
help="wfx file from calculation",
)
spec.default_output_node = "output_parameters"
spec.outputs.dynamic = True

# Exit codes
spec.exit_code(
200,
"ERROR_NO_RETRIEVED_FOLDER",
message="The retrieved folder data node could not be accessed.",
)
spec.exit_code(
210,
"ERROR_OUTPUT_MISSING",
message="The retrieved folder did not contain the output file.",
)
spec.exit_code(
211,
"ERROR_OUTPUT_LOG_READ",
message="The retrieved output log could not be read.",
)
spec.exit_code(
220,
"ERROR_OUTPUT_PARSING",
message="The output file could not be parsed.",
)
spec.exit_code(
301,
"ERROR_SCF_FAILURE",
message="The SCF did not converge and the calculation was terminated.",
)
spec.exit_code(
302,
"ERROR_ASYTOP",
message="The calculation was terminated due to a logic error in ASyTop.",
)
spec.exit_code(
303,
"ERROR_INACCURATE_QUADRATURE_CALDSU",
message="The calculation was terminated due to an inaccurate quadrature in CalDSu.",
)
spec.exit_code(
390,
"ERROR_TERMINATION",
message="The calculation was terminated due to an error.",
)
spec.exit_code(
391,
"ERROR_NO_NORMAL_TERMINATION",
message="The log did not contain 'Normal termination' (probably out of time).",
)
spec.exit_code(
410,
"ERROR_MULTIPLE_INPUT_STRUCTURES",
message="structure and structure_str were both provided as inputs. provide only one",
)

# --------------------------------------------------------------------------
def prepare_for_submission(self, folder):
"""
This is the routine to be called when you want to create
the input files and related stuff with a plugin.
:param folder: a aiida.common.folders.Folder subclass where
the plugin should put all its files.
"""

if "structure" in self.inputs and "structure_str" not in self.inputs:
structure = self.inputs.structure.get_pymatgen_molecule()
elif "structure" not in self.inputs and "structure_str" in self.inputs:
structure = self.inputs.structure_str.value
elif "structure" in self.inputs and "structure_str" in self.inputs:
return ExitCode(410)
else:
# If structure is not specified, it is read from the chk file
structure = None

# Generate the input file
input_string = GaussianWFXCalculation._render_input_string_from_params(
self.inputs.parameters.get_dict(), structure
)

with open(
folder.get_abs_path(self.INPUT_FILE), "w", encoding="utf-8"
) as out_file:
out_file.write(input_string)

settings = self.inputs.settings.get_dict() if "settings" in self.inputs else {}

# create code info
codeinfo = CodeInfo()
codeinfo.cmdline_params = settings.pop("cmdline", [])
codeinfo.code_uuid = self.inputs.code.uuid
codeinfo.stdin_name = self.INPUT_FILE
codeinfo.stdout_name = self.OUTPUT_FILE
codeinfo.withmpi = self.inputs.metadata.options.withmpi

# create calculation info
calcinfo = CalcInfo()
calcinfo.remote_copy_list = []
calcinfo.local_copy_list = []
calcinfo.uuid = self.uuid
calcinfo.cmdline_params = codeinfo.cmdline_params
calcinfo.stdin_name = self.INPUT_FILE
calcinfo.stdout_name = self.OUTPUT_FILE
calcinfo.codes_info = [codeinfo]
calcinfo.retrieve_list = [self.OUTPUT_FILE, "output.wfx"]

# symlink or copy to parent calculation
calcinfo.remote_symlink_list = []
calcinfo.remote_copy_list = []
if "parent_calc_folder" in self.inputs:
comp_uuid = self.inputs.parent_calc_folder.computer.uuid
remote_path = self.inputs.parent_calc_folder.get_remote_path()
copy_info = (comp_uuid, remote_path, self.PARENT_FOLDER_NAME)
if self.inputs.code.computer.uuid == comp_uuid:
# if running on the same computer - make a symlink
# if not - copy the folder
calcinfo.remote_symlink_list.append(copy_info)
else:
calcinfo.remote_copy_list.append(copy_info)

return calcinfo

@classmethod
def _render_input_string_from_params(cls, parameters, structure_string):
"""Generate the Gaussian input file using pymatgen."""
parameters.setdefault("dieze_tag", "#N")
parameters.setdefault("spin_multiplicity", parameters.pop("multiplicity", None))
parameters["title"] = "input generated by the aiida-gaussian plugin"
gaussian_input = GaussianInput(structure_string, **parameters)
return gaussian_input.to_str(cart_coords=True)
8 changes: 3 additions & 5 deletions src/aiida_aimall/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from aiida_submission_controller import FromGroupSubmissionController

AimqbParameters = DataFactory("aimall.aimqb")
GaussianCalculation = CalculationFactory("aimall.gaussianwfx")
GaussianCalculation = CalculationFactory("gaussian")
AimqbCalculation = CalculationFactory("aimall.aimqb")


Expand Down Expand Up @@ -473,7 +473,7 @@ class GaussianSubmissionController(FromGroupSubmissionController):
g16_sp_params: dict
wfxgroup: str
# GaussianWFXCalculation entry point as defined in aiida-aimall pyproject.toml
CALCULATION_ENTRY_POINT = "aimall.gaussianwfx"
CALCULATION_ENTRY_POINT = "gaussian"

def __init__(
self,
Expand Down Expand Up @@ -514,11 +514,9 @@ def get_inputs_and_processclass_from_extras(self, extras_values):
code = orm.load_code(self.code_label)
structure = self.get_parent_node_from_extras(extras_values)
inputs = {
"fragment_label": Str(extras_values[0]),
"code": code,
"parameters": Dict(self.g16_sp_params),
"structure_str": structure,
"wfxgroup": Str(self.wfxgroup),
"structure": structure,
"metadata": {
"options": {
"resources": {"num_machines": 1, "tot_num_mpiprocs": 1},
Expand Down
Loading

0 comments on commit 0a3ae01

Please sign in to comment.