File: py.py

package info (click to toggle)
python-ase 3.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,192 kB
  • ctags: 8,112
  • sloc: python: 93,375; sh: 99; makefile: 94
file content (21 lines) | stat: -rw-r--r-- 786 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

def write_py(fileobj, images):
    """Write to ASE-compatible python script."""
    fileobj.write('from ase import Atoms\n\n')
    fileobj.write('import numpy as np\n\n')
    
    if not isinstance(images, (list, tuple)):
        images = [images]
    fileobj.write('images = [\n')

    for image in images:
        fileobj.write("    Atoms(symbols='%s',\n"
                      "          pbc=np.%s,\n"
                      "          cell=np.array(\n      %s,\n"
                      "          positions=np.array(\n      %s),\n" % (
                          image.get_chemical_formula(mode='reduce'),
                          repr(image.pbc),
                          repr(image.cell)[6:],
                          repr(image.positions)[6:]))
        
    fileobj.write(']')