66
77from typing import Dict , Optional , Sequence
88import numpy as np
9- from copy import deepcopy
109from pymatgen .io .ase import AseAtomsAdaptor as AAA
1110from pymatgen .analysis .structure_matcher import StructureMatcher
1211from ase .io import write
1312from asimtools .utils import (
14- get_atoms , get_images , new_db
13+ get_images , new_db
1514)
1615
1716
@@ -27,6 +26,7 @@ def collect_images(
2726 energy_per_atom_limits : Optional [Sequence [float ]] = None ,
2827 force_max : Optional [float ] = None ,
2928 stress_limits : Optional [Sequence [float ]] = None ,
29+ properties : Optional [tuple ] = ('energy' , 'forces' , 'stress' ),
3030) -> Dict :
3131 """Collects images into one file/database and can split them into
3232 multiple files/databases for ML tasks
@@ -57,6 +57,8 @@ def collect_images(
5757 :type force_max: Optional[float], optional
5858 :param stress_limits: stress limits for filtering images, defaults to None
5959 :type stress_limits: Optional[Sequence[float]], optional
60+ :param properties: which of energy, force, stress to consider
61+ :type Sequence, optional
6062 :return: results
6163 :rtype: Dict
6264
@@ -72,34 +74,36 @@ def collect_images(
7274 selected_atoms = []
7375 nonselected_atoms = []
7476 for atoms in images :
75- energy = atoms .get_potential_energy ()
76- forces = atoms .get_forces ()
77- stress = atoms .get_stress ()
78-
7977 select = True
80- if energy_per_atom_limits is not None :
81- if (energy < energy_per_atom_limits [0 ]):
82- if (energy > energy_per_atom_limits [1 ]):
83- select = False
84- if force_max is not None :
85- max_force = np .max (np .linalg .norm (forces , axis = 1 ))
86- if (max_force > force_max ):
87- select = False
88- if stress_limits is not None :
89- max_stress = np .max (stress )
90- min_stress = np .min (stress )
91- if (min_stress < stress_limits [0 ]):
92- if (max_stress > stress_limits [1 ]):
78+ if 'energy' in properties :
79+ energy = atoms .get_potential_energy ()
80+ if energy_per_atom_limits is not None :
81+ if (energy < energy_per_atom_limits [0 ]):
82+ if (energy > energy_per_atom_limits [1 ]):
83+ select = False
84+ if 'forces' in properties :
85+ forces = atoms .get_forces ()
86+ if force_max is not None :
87+ max_force = np .max (np .linalg .norm (forces , axis = 1 ))
88+ if (max_force > force_max ):
9389 select = False
90+ if 'stress' in properties :
91+ stress = atoms .get_stress ()
92+ if stress_limits is not None :
93+ max_stress = np .max (stress )
94+ min_stress = np .min (stress )
95+ if (min_stress < stress_limits [0 ]):
96+ if (max_stress > stress_limits [1 ]):
97+ select = False
9498
9599 if select :
96100 if rename_keys is not None and out_format == 'extxyz' :
97101 write_kwargs ['write_info' ] = True
98- if 'energy' in rename_keys :
102+ if 'energy' in rename_keys and 'energy' in properties :
99103 atoms .info [rename_keys ['energy' ]] = energy
100- if 'forces' in rename_keys :
104+ if 'forces' in rename_keys and 'forces' in properties :
101105 atoms .arrays [rename_keys ['forces' ]] = forces
102- if 'stress' in rename_keys :
106+ if 'stress' in rename_keys and 'stress' in properties :
103107 atoms .info [rename_keys ['stress' ]] = stress
104108 selected_atoms .append (atoms )
105109 else :
0 commit comments