Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add structure import ase #1085

Merged
merged 3 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions aiida/cmdline/commands/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,7 @@ def _import_xyz(self, filename, **kwargs):

except ValueError as e:
print e
sys.exit(1)

def _import_pwi(self, filename, **kwargs):
"""
Expand All @@ -1407,10 +1408,9 @@ def _import_pwi(self, filename, **kwargs):
try:
from qe_tools.parsers.pwinputparser import PwInputFile
except ImportError:
import sys
print ("You have not installed the package qe-tools. \n"
"You can install it with: pip install qe-tools")
sys.exit(0)
sys.exit(1)

dont_store = kwargs.pop('dont_store')
view_in_ase = kwargs.pop('view')
Expand All @@ -1434,7 +1434,46 @@ def _import_pwi(self, filename, **kwargs):

except ValueError as e:
print e
sys.exit(1)

def _import_ase(self, filename, **kwargs):
"""
Imports a structure in a number of formats using the ASE routines.
"""
from os.path import abspath
from aiida.orm.data.structure import StructureData

try:
import ase.io
except ImportError:
print ("You have not installed the package ase. \n"
"You can install it with: pip install ase")
sys.exit(1)

dont_store = kwargs.pop('dont_store')
view_in_ase = kwargs.pop('view')

print 'importing structure from: \n {}'.format(abspath(filename))
filepath = abspath(filename)

try:
asecell = ase.io.read(filepath)
new_structure = StructureData(ase=asecell)

if not dont_store:
new_structure.store()
if view_in_ase:
from ase.visualize import view
view(new_structure.get_ase())
print (
' Succesfully imported structure {}, '
'(PK = {})'.format(new_structure.get_formula(), new_structure.pk)
)

except ValueError as e:
print e
sys.exit(1)

def _deposit_tcod(self, node, parameter_data=None, **kwargs):
"""
Deposition plugin for TCOD.
Expand Down
5 changes: 5 additions & 0 deletions aiida/cmdline/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

@contextmanager
def captured_output():
"""
Utility to capture stdout and sterr to two StringIOs that
are returned by the context manager, and replacing them
back once out of the context manager
"""
new_out, new_err = StringIO(), StringIO()
old_out, old_err = sys.stdout, sys.stderr
try:
Expand Down