Last active
March 31, 2016 02:27
-
-
Save unkcpz/92742d634f6e24460104de659ff4e4ac to your computer and use it in GitHub Desktop.
Aiida: template of single run. not workflows.
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 runaiida | |
# -*- conding: utf-8 -*- | |
__copyright__ = u"Copyright (c), 2015, ECOLE POLYTECHNIQUE FEDERALE DE LAUSANNE (Theory and Simulation of Materials (THEOS) and National Centre for Computational Design and Discovery of Novel Materials (NCCR MARVEL)), Switzerland and ROBERT BOSCH LLC, USA. All rights reserved." | |
__license__ = "MIT license, see LICENSE.txt file" | |
__version__ = "0.5.0" | |
__contributors__ = "Andrea Cepellotti, Giovanni Pizzi, Martin Uhrin, Nicolas Mounet, Riccardo Sabatini, Valentin Bersier" | |
# example: | |
# user$ ./pw_energy.py pw53s@rocks PbO.cif lda_hgh | |
import sys | |
import os | |
from aiida.common.example_helpers import test_and_get_code | |
from aiida.common.exceptions import NotExistent | |
import pymatgen as mg | |
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer | |
UpfData = DataFactory('upf') | |
ParameterData = DataFactory('parameter') | |
KpointsData = DataFactory('array.kpoints') | |
StructureData = DataFactory('structure') | |
try: | |
codename = sys.argv[1] | |
except IndexError: | |
codename = None | |
code = test_and_get_code(codename, expected_code_type='quantumespresso.pw') | |
try: | |
struname = sys.argv[2] # structure are file can pass to pymatgen and parse to structure class | |
except IndexError: | |
struname = None | |
# pymatgen is used for get and standarlize the primitive structure | |
mgstru = mg.Structure.from_file(struname) | |
a = SpacegroupAnalyzer(mgstru) | |
primstru = a.get_primitive_standard_structure() | |
s = StructureData(pymatgen_structure=primstru) | |
elements = list(s.get_symbols_set()) | |
# auto import pseudopotentials | |
valid_pseudo_groups = UpfData.get_upf_groups(filter_elements=elements) | |
try: | |
pseudo_family = sys.argv[3] | |
except IndexError: | |
print >> sys.stderr, "Error, auto_pseudos set to True. You therefore need to pass as second parameter" | |
print >> sys.stderr, "the pseudo family name." | |
print >> sys.stderr, "Valid UPF families are:" | |
print >> sys.stderr, "\n".join("* {}".format(i.name) for i in valid_pseudo_groups) | |
sys.exit(1) | |
try: | |
UpfData.get_upf_group(pseudo_family) | |
except NotExistent: | |
print >> sys.stderr, "auto_pseudos is set to True and pseudo_family='{}',".format(pseudo_family) | |
print >> sys.stderr, "but no group with such a name found in the DB." | |
print >> sys.stderr, "Valid UPF groups are:" | |
print >> sys.stderr, ",".join(i.name for i in valid_pseudo_groups) | |
sys.exit(1) | |
# the parameters of pw.x input | |
parameters = ParameterData(dict={ | |
'CONTROL': { | |
'calculation': 'scf', | |
'restart_mode': 'from_scratch', | |
'wf_collect': True, | |
'tstress': True, | |
'tprnfor': True, | |
}, | |
'SYSTEM': { | |
'ecutwfc': 40., | |
'ecutrho': 320., | |
}, | |
'ELECTRONS': { | |
'conv_thr': 1.e-10, | |
}}) | |
kpoints = KpointsData() | |
# method gamma only | |
#settings = ParameterData(dict={'gamma_only':True}) | |
#kpoints.set_kpoints_mesh([1,1,1]) | |
# method list | |
#import numpy | |
#kpoints.set_kpoints([[i,i,0] for i in numpy.linspace(0,1,10)], | |
# weights = [1. for i in range(10)]) | |
# method mesh | |
kpoints_mesh = 2 | |
kpoints.set_kpoints_mesh([kpoints_mesh, kpoints_mesh, kpoints_mesh]) | |
# to retrieve the bands | |
# (the object settings is optional) | |
settings_dict = {'also_bands': True} | |
settings = ParameterData(dict=settings_dict) | |
## For remote codes, it is not necessary to manually set the computer, | |
## since it is set automatically by new_calc | |
#computer = code.get_remote_computer() | |
#calc = code.new_calc(computer=computer) | |
calc = code.new_calc() | |
calc.label = "energy calc pw.x" | |
calc.description = "calculate the energy from a input file" | |
calc.set_max_wallclock_seconds(120*60) # 2hours | |
calc.set_resources({"parallel_env": 'orte', "tot_num_mpiprocs": 8}) | |
# if queue is not None: | |
# calc.set_queue_name(queue) | |
calc.use_structure(s) | |
calc.use_parameters(parameters) | |
try: | |
calc.use_pseudos_from_family(pseudo_family) | |
print "Pseudos successfully loaded from family {}".format(pseudo_family) | |
except NotExistent: | |
print ("Pseudo or pseudo family not found. You may want to load the ") | |
raise | |
calc.use_kpoints(kpoints) | |
if settings is not None: | |
calc.use_settings(settings) | |
calc.store_all() | |
print "created calculation; calc=Calculation(uuid='{}') # ID={}".format( | |
calc.uuid, calc.dbnode.pk) | |
calc.submit() | |
print "submitted calculation; calc=Calculation(uuid='{}') # ID={}".format( | |
calc.uuid, calc.dbnode.pk) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
init files. one example for cluster in office.