5
$\begingroup$

I am using the ACAT code for generating the structures.

from acat.build.ordering import SymmetricSlabOrderingGenerator as SSOG

from ase.build import fcc110

from ase.io import read

from ase.visualize import view

atoms = fcc110('Ni', (4, 4, 4), vacuum=5.)

atoms.center(axis=2)

ssog = SSOG(atoms, elements=['Ni', 'Pt'],
            symmetry='translational',
            composition={'Ni': 0.75, 'Pt': 0.25},
            repeating_size=(2, 2))

ssog.run(max_gen=50, mode='stochastic', verbose=True)

images = read('orderings.traj', index=':')

view(images)

I do not understand how to write all the generated structures to different .txt files with the format of VASP POSCAR or .xyz etc.

$\endgroup$
6
  • 1
    $\begingroup$ I don't know about SSOG, but for ASE you can use write function, for example: from ase.build import fcc110 from ase.io import read, write atoms = fcc110('Ni', (4, 4, 4), vacuum=5.) atoms.center(axis=2) write("structure.xyz", atoms) write("structure.vasp", atoms) Based on file extension the ase.io.write function will write structural data in different formats. $\endgroup$
    – Victor
    Commented Apr 12 at 9:18
  • $\begingroup$ @Victor Thank you for prompt answer but i want all random generated ( in this case 50 structure) structure write in separated files. $\endgroup$ Commented Apr 12 at 9:26
  • 2
    $\begingroup$ Ok, then you can write to separate files: from acat.build.ordering import SymmetricSlabOrderingGenerator as SSOG from ase.build import fcc110 from ase.io import read, write atoms = fcc110('Ni', (4, 4, 4), vacuum=5.) atoms.center(axis=2) ssog = SSOG(atoms, elements=['Ni', 'Pt'], symmetry='translational', composition={'Ni': 0.75, 'Pt': 0.25}, repeating_size=(2, 2)) ssog.run(max_gen=50, mode='stochastic', verbose=True) images = read('orderings.traj', index=':') ind = 0 for a in images: ind = ind + 1 s = str(ind) write("str"+s+".xyz", a) write("str"+s+".vasp", a) $\endgroup$
    – Victor
    Commented Apr 12 at 9:48
  • $\begingroup$ Please use a code block. $\endgroup$ Commented Apr 12 at 10:54
  • $\begingroup$ @RubiAgrawal Please add your orderings.traj file as a code block $\endgroup$ Commented Apr 14 at 17:29

1 Answer 1

6
$\begingroup$

You can use the following code to write the generated images to xyz files

# Write each generated structure to a separate file
for i, image in enumerate(images):
    # You can change the format to 'vasp' or 'xyz' as needed
    filename = f'structure_{i}.xyz'  # or '.vasp' for VASP POSCAR format
    write(filename, image)

Full code for reproducibility:

from acat.build.ordering import SymmetricSlabOrderingGenerator as SSOG from ase.build import fcc110 from ase.io import read, write

atoms = fcc110('Ni', (4, 4, 4), vacuum=5.) atoms.center(axis=2)

ssog = SSOG(atoms, elements=['Ni', 'Pt'],
            symmetry='translational',
            composition={'Ni': 0.75, 'Pt': 0.25},
            repeating_size=(2, 2))

ssog.run(max_gen=50, mode='stochastic', verbose=True)

# Read the trajectory file containing the generated structures 
images = read('orderings.traj', index=':')


# Write each generated structure to a separate file
for i, image in enumerate(images):
    # You can change the format to 'vasp' or 'xyz' as needed
    filename = f'structure_{i}.xyz'  # or '.vasp' for VASP POSCAR format
    write(filename, image)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .