Skip to content

cannot convert vasp MLAIMD traj to extxyz ASE format #235

@Asif-Iqbal-Bhatti

Description

@Asif-Iqbal-Bhatti

Hello,

I would like to ask, is there a way to read all the trajectories from MLAIMD and convert that to an ASE extxyz file? I have this script, but that is way slow, and I am batching to fit in memory.

'''
calc = Calculation.from_file("vaspout.h5")
print(dir(calc.energy[:]))
print(dir(calc))

def MLMD_AIMD_to_EXTXYZ(xyzpath, calc, buffer_size=5000):
#struct_tomdtraj = calc.structure[:].to_mdtraj()
#print(dir(struct_tomdtraj))
#struct_tomdtraj.save_xyz('mdtraj_data.xyz')

md_steps = calc.structure[:].number_steps()
name = calc.topology
buffer = []

for i in tqdm(range(md_steps), desc="Processing MLAIMD frames"):
    atoms = calc.structure[i].to_ase()
    energy = calc.energy[i].read()['total energy   ETOTAL']
    forces = calc.force[i].read()['forces']
    stress = calc.stress[i].read()['stress'] # in kbar with -ve being opposite to ASE

    #stress_ASE = np.array(
    #    [
    #        stress[0][0],
    #        stress[1][1],
    #        stress[2][2],
    #        stress[1][2],
    #        stress[2][0],
    #        stress[0][1],
    #    ]
    #)
    ## internal stress
    #stress_eVA3 = -1 * stress_ASE / 1602.1766208  # from kbar to eV/Angstrom^3
                
    atoms.calc = SinglePointCalculator(atoms, energy=energy, forces=forces, stress=stress)
    atoms.info = {"System": f"{name}"}
    buffer.append(atoms)

    if len(buffer) >= buffer_size:
        write(f'{xyzpath}.extxyz', buffer, append=True)
        buffer.clear()

if buffer:
    write(f'{xyzpath}', buffer, append=True)

######################################################

MLMD_AIMD_to_EXTXYZ(EXTXYZ_NAME, calc)
'''

Is there a way to do much quicker using numpy vector.

Regards,
Asif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions