/
ase_convert.py
executable file
·38 lines (31 loc) · 1.44 KB
/
ase_convert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /usr/bin/env python
from __future__ import absolute_import
import argparse
import ase.io
def convert(input_filename, output_filename, from_format=None, to_format=None):
"""Wrap ASE functions to read structure from file and write new format"""
try:
structure = ase.io.read(input_filename, format=from_format)
except:
raise Exception(
"Trouble reading input file {0}".format(input_filename))
structure.write(output_filename, format=to_format)
def main():
"""Convert from one atomistic structure format to another using ASE"""
parser = argparse.ArgumentParser(
description="Convert between crystal file formats with ASE")
parser.add_argument('input_file', type=str,
help="Path to crystal structure to be converted")
parser.add_argument('output_file', type=str,
help="Output filename")
parser.add_argument('-f', '--from_format', default=None,
help="""Input file format [If this argument is omitted,
ASE will guess]""")
parser.add_argument('-t', '--to_format', default=None,
help="""Output file format [If this argument is
omitted, ASE will guess]""")
args = parser.parse_args()
convert(args.input_file, args.output_file,
from_format=args.from_format, to_format=args.to_format)
if __name__ == '__main__':
main()