Skip to content

[Code scan] Align AbacusLite dipole support with the ksdft-only input path #7544

Description

@njzjz

This issue is a result of a Codex global repository scan.

The ASE AbacusTemplate advertises dipole as an implemented property, and get_dipole_keywords() maps it to esolver_type = tddft. However, the same write_input() path immediately rejects every non-ksdft esolver_type, so requesting the advertised dipole property deterministically raises NotImplementedError before ABACUS can run.

Property declaration and dipole keyword mapping:

class AbacusTemplate(CalculatorTemplate):
implemented_properties = [
'energy', 'forces', 'stress', 'free_energy', 'magmom', 'dipole'
]
_label = 'abacus'
def __init__(self):
super().__init__(
'abacus',
self.implemented_properties
)
self.non_convergence_ok = False
# the redirect stdout and stderr
self.inputname = 'INPUT' # hard-coded
self.outputname = f'{self._label}.out'
self.errorname = f'{self._label}.err'
# fix: inconsistent atoms order may induce bugs, here a list
# is kept to swap the order of atoms
self.atomorder = None
'''because it may be not one-to-one mapping between the property
desired to calculate and the keywords used in the calculation,
in the following a series of functions for mapping the property
calculation to the keywords settings are implemented'''
@staticmethod
def get_energy_keywords(self) -> Dict[str, str]:
return {}
@staticmethod
def get_forces_keywords(self) -> Dict[str, str]:
return {'cal_force': '1'}
@staticmethod
def get_stress_keywords(self) -> Dict[str, str]:
return {'cal_stress': '1'}
@staticmethod
def get_free_energy_keywords(self) -> Dict[str, str]:
return {}
@staticmethod
def get_magmom_keywords(self) -> Dict[str, str]:
return {'nspin': '2'}
@staticmethod
def get_dipole_keywords(self) -> Dict[str, str]:
return {'esolver_type': 'tddft', 'out_dipole': '1'}

Non-ksdft rejection in the same path:

parameters = self.get_property_keywords(parameters, properties)
# postprocess on the parameters: convert the key and values
# from any to string. For the case where the value is a
# array, convert to the string spaced by whitespace
for k, v in parameters.items():
# if the v is iterable, convert to the string spaced by whitespace
if isinstance(v, (List, Tuple, Set)):
parameters[k] = ' '.join(str(i) for i in v)
dst = directory / self.inputname
_ = file_safe_backup(dst)
# remove possible key-value pairs whose value is None
parameters = {k: v for k, v in parameters.items() if v is not None}
# FIXME: only support the ksdft esolver_type presently
if parameters.get('esolver_type', 'ksdft') != 'ksdft':
raise NotImplementedError(
'ABACUS Lite only supports the ksdft esolver_type presently, '
'which means the ABACUS should always be used as a DFT '
'calculator. For other forcefields that ABACUS supports '
'such as the LJ, DP, etc., please either use the ABACUS '
'directly, or the implementation of interfaces to ASE '
'directly.'
)

Relevant code:

implemented_properties = [
    'energy', 'forces', 'stress', 'free_energy', 'magmom', 'dipole'
]
...
def get_dipole_keywords(self) -> Dict[str, str]:
    return {'esolver_type': 'tddft', 'out_dipole': '1'}
...
if parameters.get('esolver_type', 'ksdft') != 'ksdft':
    raise NotImplementedError(...)

Impact:

ASE clients can discover or request dipole as a supported property, but the calculator cannot write a valid input for it. This creates a confusing API contract and a guaranteed runtime failure for a listed property.

Suggested fix:

Either remove dipole from implemented_properties until the non-ksdft path is supported, or special-case the dipole/TDDFT workflow so write_input() can generate the required input and read_results() can parse the result consistently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions