Skip to content

Commit

Permalink
fix deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
sphuber committed Oct 5, 2023
1 parent d3e8b04 commit 0479e08
Show file tree
Hide file tree
Showing 29 changed files with 70 additions and 55 deletions.
7 changes: 6 additions & 1 deletion aiida_common_workflows/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ def convert(self, value, param, ctx):
f'file `{value}` could not be parsed into a `StructureData`: {exception}'
) from exception

duplicate = QueryBuilder().append(StructureData, filters={'extras._aiida_hash': structure._get_hash()}).first() # pylint: disable=protected-access
duplicate = QueryBuilder().append(
StructureData,
filters={
'extras._aiida_hash': structure.base.caching._get_hash() # pylint: disable=protected-access
}
).first()

if duplicate:
return duplicate[0] # pylint: disable=unsubscriptable-object
Expand Down
4 changes: 2 additions & 2 deletions aiida_common_workflows/cli/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def cmd_plot_eos(workflow, precisions, print_table, output_file):
echo.echo_critical(
f'node {workflow.__class__.__name__}<{workflow.pk}> does not correspond to an EquationOfStateWorkChain.'
)
outputs = workflow.get_outgoing(link_type=LinkType.RETURN).nested()
outputs = workflow.base.links.get_outgoing(link_type=LinkType.RETURN).nested()

missing_outputs = tuple(output for output in ('structures', 'total_energies') if output not in outputs)
if missing_outputs:
Expand Down Expand Up @@ -107,7 +107,7 @@ def cmd_plot_dissociation_curve(workflow, precisions, print_table, output_file):
echo.echo_critical(
f'node {workflow.__class__.__name__}<{workflow.pk}> does not correspond to a DissociationCurveWorkChain.'
)
outputs = workflow.get_outgoing(link_type=LinkType.RETURN).nested()
outputs = workflow.base.links.get_outgoing(link_type=LinkType.RETURN).nested()

missing_outputs = tuple(output for output in ('distances', 'total_energies') if output not in outputs)
if missing_outputs:
Expand Down
4 changes: 2 additions & 2 deletions aiida_common_workflows/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def echo_process_results(node):
from aiida.common.links import LinkType

class_name = node.process_class.__name__
outputs = node.get_outgoing(link_type=(LinkType.CREATE, LinkType.RETURN)).all()
outputs = node.base.links.get_outgoing(link_type=(LinkType.CREATE, LinkType.RETURN)).all()

if node.is_finished and node.exit_message:
state = f'{node.process_state.value} [{node.exit_status}] `{node.exit_message}`'
Expand Down Expand Up @@ -81,7 +81,7 @@ def get_code_from_list_or_database(codes, entry_point: str):
from aiida.orm import Code, QueryBuilder

for entry in codes:
if entry.get_attribute('input_plugin') == entry_point:
if entry.base.attributes.get('input_plugin') == entry_point:
return entry

result = QueryBuilder().append(Code, filters={'attributes.input_plugin': entry_point}).first()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ def get_ts_energy(common_relax_workchain: AbinitCommonRelaxWorkChain) -> float:
if common_relax_workchain.process_class != AbinitCommonRelaxWorkChain:
return ValueError('The input workchain is not a `AbinitCommonRelaxWorkChain`')

abinit_base_wc = common_relax_workchain.get_outgoing(link_type=LinkType.CALL_WORK).one().node
abinit_base_wc = common_relax_workchain.base.links.get_outgoing(link_type=LinkType.CALL_WORK).one().node
return -abinit_base_wc.outputs.output_parameters['e_entropy']
2 changes: 1 addition & 1 deletion aiida_common_workflows/workflows/relax/abinit/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _construct_builder(self, **kwargs) -> engine.ProcessBuilder:

pseudo_family_label = protocol.pop('pseudo_family')
try:
pseudo_family = orm.Group.objects.get(label=pseudo_family_label)
pseudo_family = orm.Group.collection.get(label=pseudo_family_label)
except exceptions.NotExistent as exception:
raise ValueError(
f'required pseudo family `{pseudo_family_label}` is not installed. '
Expand Down
6 changes: 3 additions & 3 deletions aiida_common_workflows/workflows/relax/abinit/workchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
def get_stress(parameters):
"""Return the stress array from the given parameters node."""
stress = orm.ArrayData()
stress.set_array(name='stress', array=np.array(parameters.get_attribute('cart_stress_tensor')) * GPA_TO_EV_A3)
stress.set_array(name='stress', array=np.array(parameters.base.attributes.get('cart_stress_tensor')) * GPA_TO_EV_A3)
return stress


@calcfunction
def get_forces(parameters):
"""Return the forces array from the given parameters node."""
forces = orm.ArrayData()
forces.set_array(name='forces', array=np.array(parameters.get_attribute('forces')))
forces.set_array(name='forces', array=np.array(parameters.base.attributes.get('forces')))
return forces


@calcfunction
def get_total_energy(parameters):
"""Return the total energy from the given parameters node."""
return orm.Float(parameters.get_attribute('energy'))
return orm.Float(parameters.base.attributes.get('energy'))


@calcfunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_ts_energy(common_relax_workchain):
if common_relax_workchain.process_class != CastepCommonRelaxWorkChain:
return ValueError('The input workchain is not a `CastepCommonRelaxWorkChain`')

castep_base_wc = common_relax_workchain.get_outgoing(link_type=LinkType.CALL_WORK).one().node
castep_base_wc = common_relax_workchain.base.links.get_outgoing(link_type=LinkType.CALL_WORK).one().node
e_ks = castep_base_wc.outputs.output_parameters['total energy']
free_e = castep_base_wc.outputs.output_parameters['free energy']

Expand Down
4 changes: 2 additions & 2 deletions aiida_common_workflows/workflows/relax/castep/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def generate_inputs(
if isinstance(family_name, orm.Str):
family_name = family_name.value
try:
otfg_family = OTFGGroup.objects.get(label=family_name)
otfg_family = OTFGGroup.collection.get(label=family_name)
except exceptions.NotExistent as exc:
name = protocol['name']
family = protocol['relax']['base']['pseudos_family']
Expand Down Expand Up @@ -424,7 +424,7 @@ def ensure_otfg_family(family_name, force_update=False):
if isinstance(family_name, orm.Str):
family_name = family_name.value
try:
OTFGGroup.objects.get(label=family_name)
OTFGGroup.collection.get(label=family_name)
except NotExistent:
has_family = False
else:
Expand Down
4 changes: 2 additions & 2 deletions aiida_common_workflows/workflows/relax/castep/workchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_free_energy(parameters):
Return the free energy from the given parameters node.
The free energy reported by CASTEP is the one that is consistent with the forces.
"""
return orm.Float(parameters.get_attribute('free_energy'))
return orm.Float(parameters.base.attributes.get('free_energy'))


@calcfunction
Expand All @@ -62,7 +62,7 @@ def get_total_magnetization(parameters):
Return the free energy from the given parameters node.
The free energy reported by CASTEP is the one that is consistent with the forces.
"""
return orm.Float(parameters.get_attribute('spin_density'))
return orm.Float(parameters.base.attributes.get('spin_density'))


class CastepCommonRelaxWorkChain(CommonRelaxWorkChain):
Expand Down
2 changes: 1 addition & 1 deletion aiida_common_workflows/workflows/relax/cp2k/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def _get_kpoints(kpoints_distance, structure, reference_workchain):
if reference_workchain and 'cp2k__kpoints' in reference_workchain.inputs:
kpoints_mesh = KpointsData()
kpoints_mesh.set_cell_from_structure(structure)
kpoints_mesh.set_kpoints_mesh(reference_workchain.inputs.cp2k__kpoints.get_attribute('mesh'))
kpoints_mesh.set_kpoints_mesh(reference_workchain.inputs.cp2k__kpoints.base.attributes.get('mesh'))
return kpoints_mesh

if kpoints_distance:
Expand Down
2 changes: 1 addition & 1 deletion aiida_common_workflows/workflows/relax/cp2k/workchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@calcfunction
def get_total_energy(parameters):
"""Return the total energy from the given parameters node."""
return orm.Float(parameters.get_attribute('energy') * HA_TO_EV)
return orm.Float(parameters.base.attributes.get('energy') * HA_TO_EV)


@calcfunction
Expand Down
2 changes: 1 addition & 1 deletion aiida_common_workflows/workflows/relax/fleur/extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_ts_energy(common_relax_workchain):
if common_relax_workchain.process_class != WorkflowFactory('common_workflows.relax.fleur'):
return ValueError('The input workchain is not a `FleurCommonRelaxWorkChain`')

fleur_relax_wc = common_relax_workchain.get_outgoing(link_type=LinkType.CALL_WORK).one().node
fleur_relax_wc = common_relax_workchain.base.links.get_outgoing(link_type=LinkType.CALL_WORK).one().node
fleur_calc_out = fleur_relax_wc.outputs.last_scf.last_calc

output_parameters = fleur_calc_out.output_parameters
Expand Down
4 changes: 2 additions & 2 deletions aiida_common_workflows/workflows/relax/fleur/workchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ def get_forces_from_trajectory(trajectory): # pylint: disable=unused-argument
@calcfunction
def get_total_energy(parameters):
"""Calcfunction to get total energy from relax output"""
return orm.Float(parameters.get_attribute('energy'))
return orm.Float(parameters.base.attributes.get('energy'))


@calcfunction
def get_total_magnetization(parameters):
"""Return the total magnetic moment of the cell from the given parameters node."""
return orm.Float(parameters.get_attribute('total_magnetic_moment_cell'))
return orm.Float(parameters.base.attributes.get('total_magnetic_moment_cell'))


class FleurCommonRelaxWorkChain(CommonRelaxWorkChain):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _construct_builder(self, **kwargs) -> engine.ProcessBuilder:
magnetization_per_site = kwargs.get('magnetization_per_site', None)
threshold_forces = kwargs.get('threshold_forces', None)

if any(structure.get_attribute_many(['pbc1', 'pbc2', 'pbc3'])):
if any(structure.base.attributes.get_many(['pbc1', 'pbc2', 'pbc3'])):
print('Warning: PBC detected in input structure. It is not supported and thus ignored.')

# -----------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion aiida_common_workflows/workflows/relax/gpaw/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def _construct_builder( # pylint: disable=arguments-differ,too-many-locals
kpoints.set_cell_from_structure(structure)
if reference_workchain:
previous_kpoints = reference_workchain.inputs.kpoints
kpoints.set_kpoints_mesh(previous_kpoints.get_attribute('mesh'), previous_kpoints.get_attribute('offset'))
kpoints.set_kpoints_mesh(
previous_kpoints.base.attributes.get('mesh'), previous_kpoints.base.attributes.get('offset')
)
else:
kpoints.set_kpoints_mesh_from_density(protocol['kpoint_distance'])

Expand Down
2 changes: 1 addition & 1 deletion aiida_common_workflows/workflows/relax/gpaw/workchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def extract_forces_from_array(array):
@calcfunction
def extract_total_energy_from_parameters(parameters):
"""Return the total energy from the given parameters node."""
energy_cont = parameters.get_attribute('energy_contributions')
energy_cont = parameters.base.attributes.get('energy_contributions')
total_energy = energy_cont['xc'] + energy_cont['local'] + energy_cont['kinetic']
total_energy += energy_cont['external'] + energy_cont['potential'] + energy_cont['entropy (-st)']
return orm.Float(total_energy)
Expand Down
2 changes: 1 addition & 1 deletion aiida_common_workflows/workflows/relax/orca/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _construct_builder(self, **kwargs) -> engine.ProcessBuilder:
magnetization_per_site = kwargs.get('magnetization_per_site', None)

# Checks
if any(structure.get_attribute_many(['pbc1', 'pbc2', 'pbc2'])):
if any(structure.base.attributes.get_many(['pbc1', 'pbc2', 'pbc2'])):
warnings.warn('PBC detected in the input structure. It is not supported and thus is ignored.')

if protocol not in self.get_protocol_names():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ def get_ts_energy(common_relax_workchain: QuantumEspressoCommonRelaxWorkChain) -
if common_relax_workchain.process_class != QuantumEspressoCommonRelaxWorkChain:
return ValueError('The input workchain is not a `QuantumEspressoCommonRelaxWorkChain`')

qe_relax_wc = common_relax_workchain.get_outgoing(link_type=LinkType.CALL_WORK).one().node
qe_relax_wc = common_relax_workchain.base.links.get_outgoing(link_type=LinkType.CALL_WORK).one().node
return -qe_relax_wc.outputs.output_parameters['energy_smearing']
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def _construct_builder(self, **kwargs) -> engine.ProcessBuilder:
builder.base['pw']['parameters'] = orm.Dict(dict=parameters)

if reference_workchain:
relax = reference_workchain.get_outgoing(node_class=orm.WorkChainNode).one().node
relax = reference_workchain.base.links.get_outgoing(node_class=orm.WorkChainNode).one().node
base = sorted(relax.called, key=lambda x: x.ctime)[-1]
calc = sorted(base.called, key=lambda x: x.ctime)[-1]
kpoints = calc.inputs.kpoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def extract_from_trajectory(trajectory):
@calcfunction
def extract_from_parameters(parameters):
"""Return the total energy and optionally the total magnetization from the given parameters node."""
total_energy = parameters.get_attribute('energy')
total_magnetization = parameters.get_attribute('total_magnetization', None)
total_energy = parameters.base.attributes.get('energy')
total_magnetization = parameters.base.attributes.get('total_magnetization', None)

results = {'total_energy': orm.Float(total_energy)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_ts_energy(common_relax_workchain):
if common_relax_workchain.process_class != WorkflowFactory('common_workflows.relax.siesta'):
return ValueError('The input workchain is not a `CommonWorkflowSiestaWorkChain`')

siesta_base_wc = common_relax_workchain.get_outgoing(link_type=LinkType.CALL_WORK).one().node
siesta_base_wc = common_relax_workchain.base.links.get_outgoing(link_type=LinkType.CALL_WORK).one().node
e_ks = siesta_base_wc.outputs.output_parameters['E_KS']
free_e = siesta_base_wc.outputs.output_parameters['FreeE']

Expand Down
8 changes: 5 additions & 3 deletions aiida_common_workflows/workflows/relax/siesta/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _construct_builder(self, **kwargs) -> engine.ProcessBuilder:

pseudo_family = self._protocols[protocol]['pseudo_family']
try:
orm.Group.objects.get(label=pseudo_family)
orm.Group.collection.get(label=pseudo_family)
except exceptions.NotExistent as exc:
raise ValueError(
f'protocol `{protocol}` requires `pseudo_family` with name {pseudo_family} '
Expand Down Expand Up @@ -213,7 +213,7 @@ def _get_param(self, key, structure, reference_workchain): # pylint: disable=to
#the underline SiestaBaseWorkChain.
if reference_workchain is not None:
from aiida.orm import WorkChainNode
siesta_base_outs = reference_workchain.get_outgoing(node_class=WorkChainNode).one().node.outputs
siesta_base_outs = reference_workchain.base.links.get_outgoing(node_class=WorkChainNode).one().node.outputs
mesh = siesta_base_outs.output_parameters.attributes['mesh']
parameters['mesh-sizes'] = f'[{mesh[0]} {mesh[1]} {mesh[2]}]'
parameters.pop('mesh-cutoff', None)
Expand Down Expand Up @@ -281,7 +281,9 @@ def _get_kpoints(self, key, structure, reference_workchain):
kpoints_mesh = KpointsData()
kpoints_mesh.set_cell_from_structure(structure)
previous_wc_kp = reference_workchain.inputs.kpoints
kpoints_mesh.set_kpoints_mesh(previous_wc_kp.get_attribute('mesh'), previous_wc_kp.get_attribute('offset'))
kpoints_mesh.set_kpoints_mesh(
previous_wc_kp.base.attributes.get('mesh'), previous_wc_kp.base.attributes.get('offset')
)
return kpoints_mesh

if 'kpoints' in self._protocols[key]:
Expand Down
2 changes: 1 addition & 1 deletion aiida_common_workflows/workflows/relax/vasp/extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_ts_energy(common_relax_workchain):
if common_relax_workchain.process_class != WorkflowFactory('common_workflows.relax.vasp'):
return ValueError('The input workchain is not a `VaspCommonRelaxWorkChain`')

vasp_wc = common_relax_workchain.get_outgoing(link_type=LinkType.CALL_WORK).one().node
vasp_wc = common_relax_workchain.base.links.get_outgoing(link_type=LinkType.CALL_WORK).one().node
energies = vasp_wc.outputs.energies
energy_free = energies.get_array('energy_free_electronic')[0]
energy_no_entropy = energies.get_array('energy_no_entropy')[0]
Expand Down
4 changes: 3 additions & 1 deletion aiida_common_workflows/workflows/relax/vasp/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ def _construct_builder(self, **kwargs) -> engine.ProcessBuilder:
kpoints.set_cell_from_structure(structure)
if reference_workchain:
previous_kpoints = reference_workchain.inputs.kpoints
kpoints.set_kpoints_mesh(previous_kpoints.get_attribute('mesh'), previous_kpoints.get_attribute('offset'))
kpoints.set_kpoints_mesh(
previous_kpoints.base.attributes.get('mesh'), previous_kpoints.base.attributes.get('offset')
)
else:
kpoints.set_kpoints_mesh_from_density(protocol['kpoint_distance'])
builder.kpoints = kpoints
Expand Down
2 changes: 1 addition & 1 deletion aiida_common_workflows/workflows/relax/wien2k/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _construct_builder(self, **kwargs) -> engine.ProcessBuilder:
inpdict['-nometal'] = True
if reference_workchain: # ref. workchain is passed as input
# derive Rmt's from the ref. workchain and pass as input
w2k_wchain = reference_workchain.get_outgoing(node_class=orm.WorkChainNode).one().node
w2k_wchain = reference_workchain.base.links.get_outgoing(node_class=orm.WorkChainNode).one().node
ref_wrkchn_res_dict = w2k_wchain.outputs.workchain_result.get_dict()
rmt = ref_wrkchn_res_dict['Rmt']
atm_lbl = ref_wrkchn_res_dict['atom_labels']
Expand Down
2 changes: 1 addition & 1 deletion docs/source/workflows/composite/dc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ A template script to retrieve the results follows:
node = load_node(<IDN>) # <IDN> is an identifier (PK, uuid, ..) of a completed DC workchain
outputs = node.get_outgoing(link_type=LinkType.RETURN).nested()
outputs = node.base.links.get_outgoing(link_type=LinkType.RETURN).nested()
distances = []
energies = []
Expand Down
2 changes: 1 addition & 1 deletion docs/source/workflows/composite/eos.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ A template script to retrieve the results follows:
node = load_node(<IDN>) # <IDN> is an identifier (PK, uuid, ..) of a completed EoS workchain
outputs = node.get_outgoing(link_type=LinkType.RETURN).nested()
outputs = node.base.links.get_outgoing(link_type=LinkType.RETURN).nested()
volumes = []
energies = []
Expand Down
Loading

0 comments on commit 0479e08

Please sign in to comment.