From 86a8b85e3f4f6a89f5f3c742f991f7bf95e38fcf Mon Sep 17 00:00:00 2001 From: Anton Domnin Date: Tue, 30 Jul 2024 02:05:29 +0300 Subject: [PATCH 1/5] fix for "Excepted" error in phonons calculations (Issue 71) --- aiida_crystal_dft/parsers/cry_pycrystal.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/aiida_crystal_dft/parsers/cry_pycrystal.py b/aiida_crystal_dft/parsers/cry_pycrystal.py index 6ca06ef..222f500 100644 --- a/aiida_crystal_dft/parsers/cry_pycrystal.py +++ b/aiida_crystal_dft/parsers/cry_pycrystal.py @@ -68,7 +68,7 @@ def parse(self, **kwargs): except out.CRYSTOUT_Error as ex: if 'Inadequate elastic calculation' in ex.msg: return self.exit_codes.ERROR_REOPTIMIZATION_NEEDED - + # TODO: refactor this later # Check for error file contents scf_failed = False if 'fort.87' in folder.list_object_names(): @@ -157,7 +157,8 @@ def parse_out_wavefunction(self, f): return None return DataFactory('singlefile')(file=f) - def parse_out_trajectory(self, _): +def parse_out_trajectory(self, _): + try: ase_structs = self.stdout_parser.get_trajectory() if not ase_structs: return None @@ -165,3 +166,13 @@ def parse_out_trajectory(self, _): traj = DataFactory('array.trajectory')() traj.set_structurelist(structs) return traj + except ValueError as e: + # Fix for calculation with SCELPHO keyword; + # Scince supercell have more atoms than regular cell; + # traj.set_structurelist(structs) will throw an error https://github.com/aiidateam/aiida-core/blob/71422eb872040a9ba23047d2ec031f6deaa6a7cc/src/aiida/orm/nodes/data/array/trajectory.py#L202 + # There are no reason for tracking trajectory in phonon calculation, so it will return None + if "Phonon" in self._node.label: + self._logger.warning(f"Caught ValueError for node with label '{self._node.label}': {e}") + return None + else: + raise e From b19ec40fa93504ca8aba365b09a0ea4bd37b6375 Mon Sep 17 00:00:00 2001 From: Anton Domnin Date: Tue, 30 Jul 2024 13:32:59 +0300 Subject: [PATCH 2/5] fix for [issue 71](https://github.com/tilde-lab/aiida-crystal-dft/issues/71) --- aiida_crystal_dft/parsers/cry_pycrystal.py | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/aiida_crystal_dft/parsers/cry_pycrystal.py b/aiida_crystal_dft/parsers/cry_pycrystal.py index 222f500..803244d 100644 --- a/aiida_crystal_dft/parsers/cry_pycrystal.py +++ b/aiida_crystal_dft/parsers/cry_pycrystal.py @@ -157,22 +157,22 @@ def parse_out_wavefunction(self, f): return None return DataFactory('singlefile')(file=f) -def parse_out_trajectory(self, _): - try: - ase_structs = self.stdout_parser.get_trajectory() - if not ase_structs: - return None - structs = [DataFactory('structure')(ase=struct) for struct in ase_structs] - traj = DataFactory('array.trajectory')() - traj.set_structurelist(structs) - return traj - except ValueError as e: - # Fix for calculation with SCELPHO keyword; - # Scince supercell have more atoms than regular cell; - # traj.set_structurelist(structs) will throw an error https://github.com/aiidateam/aiida-core/blob/71422eb872040a9ba23047d2ec031f6deaa6a7cc/src/aiida/orm/nodes/data/array/trajectory.py#L202 - # There are no reason for tracking trajectory in phonon calculation, so it will return None - if "Phonon" in self._node.label: - self._logger.warning(f"Caught ValueError for node with label '{self._node.label}': {e}") - return None - else: - raise e + def parse_out_trajectory(self, _): + try: + ase_structs = self.stdout_parser.get_trajectory() + if not ase_structs: + return None + structs = [DataFactory('structure')(ase=struct) for struct in ase_structs] + traj = DataFactory('array.trajectory')() + traj.set_structurelist(structs) + return traj + except ValueError as e: + # Fix for calculation with SCELPHO keyword; + # Scince supercell have more atoms than regular cell; + # traj.set_structurelist(structs) will throw an error https://github.com/aiidateam/aiida-core/blob/71422eb872040a9ba23047d2ec031f6deaa6a7cc/src/aiida/orm/nodes/data/array/trajectory.py#L202 + # There are no reason for tracking trajectory in phonon calculation, so it will return None + if "Phonon" in self._node.label: + self._logger.warning(f"Caught ValueError for node with label '{self._node.label}': {e}") + return None + else: + raise e From 9d7eb9a3f05a12002310babb880dcab960bc9961 Mon Sep 17 00:00:00 2001 From: Anton Domnin Date: Tue, 20 Aug 2024 19:18:03 +0300 Subject: [PATCH 3/5] Improved if/else statement --- aiida_crystal_dft/parsers/cry_pycrystal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aiida_crystal_dft/parsers/cry_pycrystal.py b/aiida_crystal_dft/parsers/cry_pycrystal.py index 803244d..4aa2b37 100644 --- a/aiida_crystal_dft/parsers/cry_pycrystal.py +++ b/aiida_crystal_dft/parsers/cry_pycrystal.py @@ -169,9 +169,9 @@ def parse_out_trajectory(self, _): except ValueError as e: # Fix for calculation with SCELPHO keyword; # Scince supercell have more atoms than regular cell; - # traj.set_structurelist(structs) will throw an error https://github.com/aiidateam/aiida-core/blob/71422eb872040a9ba23047d2ec031f6deaa6a7cc/src/aiida/orm/nodes/data/array/trajectory.py#L202 + # traj.set_structurelist(structs) will throw an error https://github.com/aiidateam/aiida-core/blob/71422eb872040a9ba23047d2ec031f6deaa6a7cc/src/aiida/orm/nodes/data/array/trajectory.py#L202 # There are no reason for tracking trajectory in phonon calculation, so it will return None - if "Phonon" in self._node.label: + if self.stdout_parser.info['phonons']['modes']: self._logger.warning(f"Caught ValueError for node with label '{self._node.label}': {e}") return None else: From 5ff019ec2f5ecc44bec6df4faa7abd0fc81738b9 Mon Sep 17 00:00:00 2001 From: Anton Domnin Date: Wed, 21 Aug 2024 01:06:39 +0300 Subject: [PATCH 4/5] improved if/else statement --- aiida_crystal_dft/parsers/cry_pycrystal.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aiida_crystal_dft/parsers/cry_pycrystal.py b/aiida_crystal_dft/parsers/cry_pycrystal.py index 4aa2b37..8437107 100644 --- a/aiida_crystal_dft/parsers/cry_pycrystal.py +++ b/aiida_crystal_dft/parsers/cry_pycrystal.py @@ -171,7 +171,8 @@ def parse_out_trajectory(self, _): # Scince supercell have more atoms than regular cell; # traj.set_structurelist(structs) will throw an error https://github.com/aiidateam/aiida-core/blob/71422eb872040a9ba23047d2ec031f6deaa6a7cc/src/aiida/orm/nodes/data/array/trajectory.py#L202 # There are no reason for tracking trajectory in phonon calculation, so it will return None - if self.stdout_parser.info['phonons']['modes']: + modes = self.stdout_parser.info['phonons'].get(['modes'], {}) + if modes and len(modes) > 1: self._logger.warning(f"Caught ValueError for node with label '{self._node.label}': {e}") return None else: From 95fd61bf9612bce7a21441fcd2c608bed9a80f2f Mon Sep 17 00:00:00 2001 From: Evgeny Blokhin Date: Wed, 21 Aug 2024 16:45:51 +0200 Subject: [PATCH 5/5] Polish an exceptional case handling (NB any supercell calculations can be impacted) --- aiida_crystal_dft/parsers/cry_pycrystal.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/aiida_crystal_dft/parsers/cry_pycrystal.py b/aiida_crystal_dft/parsers/cry_pycrystal.py index 8437107..a14c9f1 100644 --- a/aiida_crystal_dft/parsers/cry_pycrystal.py +++ b/aiida_crystal_dft/parsers/cry_pycrystal.py @@ -68,7 +68,7 @@ def parse(self, **kwargs): except out.CRYSTOUT_Error as ex: if 'Inadequate elastic calculation' in ex.msg: return self.exit_codes.ERROR_REOPTIMIZATION_NEEDED - # TODO: refactor this later + # Check for error file contents scf_failed = False if 'fort.87' in folder.list_object_names(): @@ -166,14 +166,10 @@ def parse_out_trajectory(self, _): traj = DataFactory('array.trajectory')() traj.set_structurelist(structs) return traj - except ValueError as e: - # Fix for calculation with SCELPHO keyword; - # Scince supercell have more atoms than regular cell; - # traj.set_structurelist(structs) will throw an error https://github.com/aiidateam/aiida-core/blob/71422eb872040a9ba23047d2ec031f6deaa6a7cc/src/aiida/orm/nodes/data/array/trajectory.py#L202 - # There are no reason for tracking trajectory in phonon calculation, so it will return None - modes = self.stdout_parser.info['phonons'].get(['modes'], {}) - if modes and len(modes) > 1: - self._logger.warning(f"Caught ValueError for node with label '{self._node.label}': {e}") + except ValueError as exc: + # fix for SCELPHONO keyword, since a supercell has more atoms than a regular cell + bz_points = self.stdout_parser.info['phonons'].get(['modes'], {}) + if bz_points and len(bz_points) > 1: return None else: - raise e + raise exc