|
68 | 68 | __ASE__ = True |
69 | 69 | try: |
70 | 70 | import ase, ase.io |
| 71 | + import ase.calculators.singlepoint |
71 | 72 | except: |
72 | 73 | __ASE__ = False |
73 | 74 |
|
@@ -788,6 +789,44 @@ def save_bin(self, data_dir, population_id = 1): |
788 | 789 | else: |
789 | 790 | print('NOOO WHAT IS HAPPENING') |
790 | 791 | 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 | + |
791 | 830 | def save_enhanced_xyz(self, filename, append_mode = True, stress_key = "virial", forces_key = "force", energy_key = "energy"): |
792 | 831 | """ |
793 | 832 | Save the ensemble as an enhanced xyz. |
|
0 commit comments