Last active
December 21, 2015 11:38
-
-
Save shyuep/6299836 to your computer and use it in GitHub Desktop.
A simple, no-dependencies script to convert a structure to and from various formats using the MAVRL's matgenie REST interface.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import json | |
import urllib | |
import urllib2 | |
import sys | |
if len(sys.argv) != 4: | |
print('Usage is "python convert_struct.py filename input_format output_format".' | |
'Input/output formats should be any one of poscar, cif, cssr or mson') | |
sys.exit(-1) | |
url = "http://mavrl.org/matgenie/convert" | |
with open(sys.argv[1]) as f: | |
content = f.read() | |
data = urllib.urlencode({"input-format": sys.argv[2], "output-format": sys.argv[3], "file-content": content}) | |
req = urllib2.Request(url, data) | |
response = urllib2.urlopen(req) | |
data = json.loads(response.read()) | |
if response.getcode() == 200: | |
print data["converted-file"] | |
else: | |
print "Error has occured : {}".format(data["error"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment