Skip to content

Commit

Permalink
ATAT SQS file converter
Browse files Browse the repository at this point in the history
  • Loading branch information
ajjackson committed Mar 1, 2017
1 parent 70769e0 commit 1e18b96
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
67 changes: 67 additions & 0 deletions mctools/sqs_read.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#! /usr/bin/env python
from __future__ import print_function

import argparse
import numpy as np
import ase.atoms
import ase.build
import ase.visualize

def atoms_from_sqs(filename):

with open(filename, 'r') as f:
lines = f.readlines()
lines = [line.split() for line in lines]

basis = np.matrix([list(map(float, line)) for line in lines[:3]])
scell = np.matrix([list(map(float, line)) for line in lines[3:6]])

spositions = [np.matrix(list(map(float, line[:3]))) for line in lines[6:]]
symbols = [line[-1] for line in lines[6:]]

supercell = scell * basis
positions = spositions * basis
atoms = ase.atoms.Atoms(symbols=symbols,
cell=supercell,
positions=positions,
pbc=True)

return atoms

def txt_display(atoms):
print("Unit cell:")
print(atoms.cell)
print("Positions")
atoms = ase.build.sort(atoms)
for atom in atoms:

print(atom.position, atom.symbol)

def main():
parser = argparse.ArgumentParser()
parser.add_argument('filename', nargs='?', default='bestsqs.out',
help="Input file generated by ATAT")
parser.add_argument('--output', '-o', default=None,
help="If specified, write to this filename")
parser.add_argument('--gui', '-g', action='store_true',
help="Show structure in ASE-GUI")

args = parser.parse_args()

atoms = atoms_from_sqs(args.filename)

if args.output is not None:
# Write file with vasp5 flag if supported
try:
atoms.write(args.output, sort=True, vasp5=True)
except TypeError:
atoms = ase.build.sort(atoms)
atoms.write(args.output)
else:
txt_display(atoms)

if args.gui:
ase.visualize.view(atoms)

if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
'get-primitive = mctools.get_primitive:main',
'get-spacegroup = mctools.get_spacegroup:main',
'get-vbm = mctools.get_vbm:main',
'sqs-read = mctools.sqs_read:main',
'sendto = mctools.sendto:main',
'vasp-charge = mctools.vasp_charge:main',
'vectors = mctools.vectors:main'
Expand Down

0 comments on commit 1e18b96

Please sign in to comment.