Skip to content

Commit 147b87c

Browse files
Merge branch 'master' into Diegom_sobol
2 parents 3113b3e + fcea929 commit 147b87c

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

Modules/AdvancedCalculations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def get_optical_spectrum(ensemble, w_array = None):
307307
""".format(i)
308308
raise ValueError(ERR)
309309

310-
data = ensemble.all_properties[i]['epsilon']
310+
data = np.array(ensemble.all_properties[i]['epsilon'])
311311

312312
if w_data is None:
313313
w_data = data[:,0]

Modules/Ensemble.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
__ASE__ = True
6969
try:
7070
import ase, ase.io
71+
import ase.calculators.singlepoint
7172
except:
7273
__ASE__ = False
7374

@@ -788,6 +789,44 @@ def save_bin(self, data_dir, population_id = 1):
788789
else:
789790
print('NOOO WHAT IS HAPPENING')
790791
print(self.all_properties)
792+
793+
def save_extxyz(self, filename, append_mode = True):
794+
"""
795+
SAVE INTO EXTXYZ FORMAT
796+
=======================
797+
798+
ASE extxyz format is used for build the training set for the nequip and allegro neural network potentials.
799+
800+
Parameters
801+
----------
802+
filename : str
803+
The path to the .extxyz file containing the ensemble
804+
append_mode: bool
805+
If true the ensemble is appended
806+
"""
807+
808+
if not __ASE__:
809+
raise ImportError("Error, this function requires ASE installed")
810+
811+
812+
ase_structs = []
813+
814+
for i, s in enumerate(self.structures):
815+
energy = self.energies[i] * Rydberg # Ry -> eV
816+
forces = self.forces[i, :, :] * Rydberg # Ry/A -> eV/A
817+
stress = self.stresses[i, :, :] * Rydberg / Bohr**3 # Ry/Bohr^3 -> eV/A^3
818+
struct = s.get_ase_atoms()
819+
820+
calculator = ase.calculators.singlepoint.SinglePointCalculator(struct, energy = energy,
821+
forces = forces, stress = CC.Methods.transform_voigt(stress))
822+
823+
struct.set_calculator(calculator)
824+
ase_structs.append(struct)
825+
826+
# Now save the extended xyz
827+
ase.io.write(filename, ase_structs, format = "extxyz", append = append_mode)
828+
829+
791830
def save_enhanced_xyz(self, filename, append_mode = True, stress_key = "virial", forces_key = "force", energy_key = "energy"):
792831
"""
793832
Save the ensemble as an enhanced xyz.

0 commit comments

Comments
 (0)