Skip to content

Commit

Permalink
precommit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kmlefran committed Sep 11, 2023
1 parent a7b037c commit e2bf3f8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 223 deletions.
106 changes: 1 addition & 105 deletions aiida_aimall/calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,114 +97,10 @@ def prepare_for_submission(self, folder):
# Prepare a `CalcInfo` to be returned to the engine
calcinfo = datastructures.CalcInfo()
calcinfo.codes_info = [codeinfo] # list since can involve more than one
# files are already stored in AiiDA file repository, can use local_copy_list to pass the along
# calcinfo.local_copy_list = [
# (
# self.inputs.file.uuid,
# self.inputs.file.filename,
# ),
# ]
# which files to retrieve from directory where job ran

calcinfo.retrieve_list = [
self.OUTPUT_FILE.replace("out", "sum"),
self.OUTPUT_FILE.replace(".out", "_atomicfiles"),
]

return calcinfo

# def cli_options(parameters):
# """Return command line options for parameters dictionary.

# :param dict parameters: dictionary with command line parameters
# """
# options = [f'-{key}={value}' for key,value in parameters.items()]
# for key, value in parameters.items():
# # Could validate: is key a known command-line option?
# options.append(f'-{key}={value}')
# elif isinstance(value, str):
# # Could validate: is value a valid regular expression?
# options.append(f'--{key}')
# options.append(value)

# return options


# class DiffCalculation(CalcJob):
# """
# AiiDA calculation plugin wrapping the diff executable.

# Simple AiiDA plugin wrapper for 'diffing' two files.
# """

# @classmethod
# def define(cls, spec):
# """Define inputs and outputs of the calculation."""
# super().define(spec)

# # set default values for AiiDA options
# spec.inputs["metadata"]["options"]["resources"].default = {
# "num_machines": 1,
# "num_mpiprocs_per_machine": 1,
# }
# spec.inputs["metadata"]["options"]["parser_name"].default = "aimall"

# # new ports
# spec.input(
# "metadata.options.output_filename", valid_type=str, default="patch.diff"
# )
# spec.input(
# "parameters",
# valid_type=DiffParameters,
# help="Command line parameters for diff",
# )
# spec.input(
# "file1", valid_type=SinglefileData, help="First file to be compared."
# )
# spec.input(
# "file2", valid_type=SinglefileData, help="Second file to be compared."
# )
# spec.output(
# "aimall",
# valid_type=SinglefileData,
# help="diff between file1 and file2.",
# )

# spec.exit_code(
# 300,
# "ERROR_MISSING_OUTPUT_FILES",
# message="Calculation did not produce all expected output files.",
# )

# def prepare_for_submission(self, folder):
# """
# Create input files.

# :param folder: an `aiida.common.folders.Folder` where the plugin should temporarily place all files
# needed by the calculation.
# :return: `aiida.common.datastructures.CalcInfo` instance
# """
# codeinfo = datastructures.CodeInfo()
# codeinfo.cmdline_params = self.inputs.parameters.cmdline_params(
# file1_name=self.inputs.file1.filename, file2_name=self.inputs.file2.filename
# )
# codeinfo.code_uuid = self.inputs.code.uuid
# codeinfo.stdout_name = self.metadata.options.output_filename

# # Prepare a `CalcInfo` to be returned to the engine
# calcinfo = datastructures.CalcInfo()
# calcinfo.codes_info = [codeinfo]
# calcinfo.local_copy_list = [
# (
# self.inputs.file1.uuid,
# self.inputs.file1.filename,
# self.inputs.file1.filename,
# ),
# (
# self.inputs.file2.uuid,
# self.inputs.file2.filename,
# self.inputs.file2.filename,
# ),
# ]
# calcinfo.retrieve_list = [self.metadata.options.output_filename]

# return calcinfo
104 changes: 14 additions & 90 deletions aiida_aimall/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Optional("iasmesh"): str,
Optional("capture"): str,
Optional("boaq"): str,
Optional("ehren"):int,
Optional("ehren"): int,
Optional("feynman"): bool,
Optional("iasprops"): bool,
Optional("magprops"): str,
Expand All @@ -31,7 +31,7 @@
Optional("f2wonly"): bool,
Optional("atoms"): str,
Optional("mir"): float,
Optional("cpconn"): str,
Optional("cpconn"): str,
Optional("intveeaa"): str,
Optional("atlaprhocps"): bool,
Optional("wsp"): bool,
Expand All @@ -42,34 +42,31 @@
Optional("verifyw"): str,
Optional("saw"): bool,
Optional("autonnacps"): bool,
# Optional("help"), commented, these are options
# Optional("console"),
# Optional("newconsole"),
# Optional("run"),
# Optional("nogui"),
}

class AimqbParameters(Dict): # pylint: disable=too-many-ancestors

class AimqbParameters(Dict): # pylint: disable=too-many-ancestors
"""
Command line options for aimqb.
This class represents a python dictionary used to
This class represents a python dictionary used to
pass command line options to the executable.
"""

schema = Schema(cmdline_options)
def __init__(self,dict=None,**kwargs):
"""
Constructor for the data class

def __init__(self, parameter_dict=None, **kwargs):
"""Constructor for the data class
Usage: ``AimqbParameters(dict{'ignore-case': True})``
:param parameters_dict: dictionary with commandline parameters
:param type parameters_dict: dict
"""
dict=self.validate(dict)
super().__init__(dict=dict, **kwargs)
parameter_dict = self.validate(parameter_dict)
super().__init__(dict=parameter_dict, **kwargs)

def validate(self, parameters_dict):
"""Validate command line options.
Expand All @@ -96,7 +93,7 @@ def cmdline_params(self, file_name):

pm_dict = self.get_dict()
for key, value in pm_dict.items():
parameters += [f'-{key}={value}']
parameters += [f"-{key}={value}"]
parameters += ["-nogui"]
parameters += [file_name]

Expand All @@ -114,76 +111,3 @@ def __str__(self):
string = super().__str__()
string += "\n" + str(self.get_dict())
return string

# class DiffParameters(Dict): # pylint: disable=too-many-ancestors
# """
# Command line options for diff.

# This class represents a python dictionary used to
# pass command line options to the executable.
# """

# # "voluptuous" schema to add automatic validation
# schema = Schema(cmdline_options)

# # pylint: disable=redefined-builtin
# def __init__(self, dict=None, **kwargs):
# """
# Constructor for the data class

# Usage: ``DiffParameters(dict{'ignore-case': True})``

# :param parameters_dict: dictionary with commandline parameters
# :param type parameters_dict: dict

# """
# dict = self.validate(dict)
# super().__init__(dict=dict, **kwargs)

# def validate(self, parameters_dict):
# """Validate command line options.

# Uses the voluptuous package for validation. Find out about allowed keys using::

# print(DiffParameters).schema.schema

# :param parameters_dict: dictionary with commandline parameters
# :param type parameters_dict: dict
# :returns: validated dictionary
# """
# return DiffParameters.schema(parameters_dict)

# def cmdline_params(self, file1_name, file2_name):
# """Synthesize command line parameters.

# e.g. [ '--ignore-case', 'filename1', 'filename2']

# :param file_name1: Name of first file
# :param type file_name1: str
# :param file_name2: Name of second file
# :param type file_name2: str

# """
# parameters = []

# pm_dict = self.get_dict()
# for option, enabled in pm_dict.items():
# if enabled:
# parameters += ["-" + option]

# parameters += [file1_name, file2_name]

# return [str(p) for p in parameters]

# def __str__(self):
# """String representation of node.

# Append values of dictionary to usual representation. E.g.::

# uuid: b416cbee-24e8-47a8-8c11-6d668770158b (pk: 590)
# {'ignore-case': True}

# """
# string = super().__str__()
# string += "\n" + str(self.get_dict())
# return string
68 changes: 41 additions & 27 deletions aiida_aimall/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
Register parsers via the "aiida.parsers" entry point in setup.json.
"""

from subproptools import qtaimExtract as qt

from aiida.common import exceptions
from aiida.engine import ExitCode
from aiida.orm import SinglefileData, Dict
from aiida.orm import Dict, SinglefileData
from aiida.parsers.parser import Parser
from aiida.plugins import CalculationFactory
import io
import re
from subproptools import qtaimExtract as qt

# from aiida.engine import ExitCode


AimqbCalculation = CalculationFactory("aimall")

Expand All @@ -19,9 +21,7 @@ class AimqbBaseParser(Parser):
"""
Parser class for parsing output of calculation.
"""
#before parser called, self.retrieved - isntance of FolderData of output files that CalcJob instructed to receive
#provides means to open any file it contains
#self.node - the calcjobNode representing the finished calculation

def __init__(self, node):
"""
Initialize Parser instance
Expand All @@ -36,19 +36,21 @@ def __init__(self, node):
raise exceptions.ParsingError("Can only parse AimqbCalculation")

def parse(self, **kwargs):
"""
Parse outputs, store results in database.
"""Parse outputs, store results in database.
:returns: an exit code, if parsing fails (or nothing if parsing succeeds)
"""
#convenience method to get filename of output file
# convenience method to get filename of output file
# output_filename = self.node.get_option("output_filename")

output_filename = self.node.process_class.OUTPUT_FILE

# Check that folder content is as expected
files_retrieved = self.retrieved.list_object_names()
files_expected = [output_filename.replace('out','sum'),output_filename.replace('.out','_atomicfiles')]
files_expected = [
output_filename.replace("out", "sum"),
output_filename.replace(".out", "_atomicfiles"),
]
# Note: set(A) <= set(B) checks whether A is a subset of B
print(files_retrieved)
print(files_expected)
Expand All @@ -62,32 +64,44 @@ def parse(self, **kwargs):
# add output file
self.logger.info(f"Parsing '{output_filename}'")
OutFolderData = self.retrieved
with OutFolderData.open(output_filename.replace('out','sum'), "rb") as handle:
with OutFolderData.open(output_filename.replace("out", "sum"), "rb") as handle:
output_node = SinglefileData(file=handle)
sum_lines = output_node.get_content()
self.outputs.atomic_properties = self._parse_atomic_props(sum_lines)
self.outputs.bcp_properties = self._parse_bcp_props(sum_lines)
self.outputs.cc_properties = self._parse_cc_props(OutFolderData)
self.outputs.cc_properties = self._parse_cc_props()
# at1_key = list(self.outputs.atomic_properties.keys())[0].str.lower()
# at_1_agpviz = output_filename.replace('.out','_atomicfiles') + '/' + at1_key + '.agpviz'

#first argument is name for link that connects calculation and data node
#second argument is node that should be recorded as output
# first argument is name for link that connects calculation and data node
# second argument is node that should be recorded as output
# self.out("aimall", output_node)

return ExitCode(0)
def _parse_cc_props(self, OutFolderData):
return # ExitCode(0)

def _parse_cc_props(self):
output_filename = self.node.process_class.OUTPUT_FILE
atom_list = list(self.outputs.atomic_properties.keys())
cc_dict = {x :qt.get_atom_vscc(filename = self.retrieved.get_object_content(output_filename.replace('.out','_atomicfiles') + '/' + x.lower() + '.agpviz').split('\n'),
atomLabel = x,type='vscc',atomicProps = self.outputs.atomic_properties.get_dict(),is_lines_data=True) for x in atom_list}
cc_dict = {
x: qt.get_atom_vscc(
filename=self.retrieved.get_object_content(
output_filename.replace(".out", "_atomicfiles")
+ "/"
+ x.lower()
+ ".agpviz"
).split("\n"),
atomLabel=x,
type="vscc",
atomicProps=self.outputs.atomic_properties.get_dict(),
is_lines_data=True,
)
for x in atom_list
}
return Dict(dict=cc_dict)

def _parse_atomic_props(self, sum_file_string):
return Dict(dict=qt.get_atomic_props(sum_file_string.split('\n')))
return Dict(dict=qt.get_atomic_props(sum_file_string.split("\n")))

def _parse_bcp_props(self, sum_file_string):
bcp_list = qt._find_all_connections(sum_file_string.split('\n'))
return Dict(dict=qt.get_selected_bcps(sum_file_string.split('\n'),bcp_list))

bcp_list = qt.find_all_connections(sum_file_string.split("\n"))
return Dict(dict=qt.get_selected_bcps(sum_file_string.split("\n"), bcp_list))
5 changes: 4 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ def clear_database_auto(clear_database): # pylint: disable=unused-argument
@pytest.fixture(scope="function")
def aimall_code(aiida_local_code_factory):
"""Get a aimall code."""
return aiida_local_code_factory(executable="aimqb", entry_point="aimall")
return aiida_local_code_factory(
executable="/Applications/AIMAll/AIMQB.app/Contents/MacOS/aimqb",
entry_point="aimall",
)

0 comments on commit e2bf3f8

Please sign in to comment.