Skip to content

Instantly share code, notes, and snippets.

@shyuep
Last active December 21, 2015 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shyuep/6299836 to your computer and use it in GitHub Desktop.
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.
#!/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