This page was generated from docs/source/user_guide/calc_basic.ipynb,
with configuration: sphinx_ipypublish_all.ext.noexec
Basic Calculation Plugin¶
The crystal17.basic
plugin is the simplest calculation plugin. It
accepts as input:
a pre-written
main.d12
file and,(optionally) a
main.gui
file with geometry, to accompany amain.d12
file containing theEXTERNAL
keyword.
Initial Setup¶
To run a computation, first ensure AiiDA is running:
In:
!verdi status
✓ profile: On profile test_crystal17
✓ repository: /Users/cjs14/GitHub/aiida-cjs-working/databases/aiida/.aiida/repository/test_crystal17
✓ postgres: Connected as cjs14@localhost:5432
✓ rabbitmq: Connected to amqp://127.0.0.1?heartbeat=600
✓ daemon: Daemon is running as PID 28308 since 2019-07-07 04:06:37
See also
AiiDA documentation: Quick installation
If aiida-crystal17
is installed, the crystal17.basic
computation
should be available:
In:
!verdi plugin list aiida.calculations crystal17.basic
Inputs
code: required Code The Code to use for this job.
input_file: required SinglefileData the input .d12 file content.
input_external: optional SinglefileData optional input fort.34 (gui) file content (for use with EXTERNAL keyword).
metadata: optional
Outputs
remote_folder: required RemoteData Input files necessary to run the process will be stored in this folder node ...
results: required Dict the data extracted from the main output file
retrieved: required FolderData Files that are retrieved by the daemon will be stored in this node. By defa ...
structure: optional StructureData the structure output from the calculation
symmetry: optional SymmetryData the symmetry data from the calculation
Exit codes
1: The process has failed with an unspecified error.
2: The process failed with legacy failure mode.
10: The process returned an invalid output.
11: The process did not register a required output.
200: The retrieved folder data node could not be accessed.
210: The main (stdout) output file was not found
211: The temporary retrieved folder was not found
300: An error was flagged trying to parse the crystal exec stdout file
301: An error occurred parsing the 'opta'/'optc' geomerty files
350: The input file could not be read by crystal
351: Crystal could not find the required wavefunction file
400: The calculation stopped prematurely because it ran out of walltime.
401: The calculation stopped prematurely because it ran out of memory.
402: The calculation stopped prematurely because it ran out of virtual memory.
411: Scf convergence did not finalise (usually due to reaching step limit)
412: Geometry convergence did not finalise (usually due to reaching step limit)
413: An error encountered usually during geometry optimisation
414: An error was encountered during an scf computation
415: An unknown error was encountered, causing the mpi to abort
499: The main crystal output file flagged an unhandled error
510: Inconsistency in the input and output symmetry
520: Primitive symmops were not found in the output file
To use the python interface, first ensure a profile is loaded in the python kernel, and import the required modules:
In:
from aiida import load_profile
profile = load_profile()
profile.name
Out:
'test_crystal17'
In:
import os
from aiida_crystal17.common import display_json
from aiida_crystal17.tests import TEST_FILES
from aiida.orm import Code
from aiida.engine import run_get_node
from aiida.plugins import DataFactory
Input Creation¶
An Code
node should be set up in
advance, to use the crystal17.basic
calculation plugin, and call the
runcry17
executable (or mock_runcry17
used here for test
purposes).
In:
from aiida_crystal17.tests.utils import get_or_create_local_computer, get_or_create_code
computer = get_or_create_local_computer('work_directory', 'localhost')
code = get_or_create_code('crystal17.basic', computer, 'mock_crystal17')
code.get_full_text_info()
Out:
[['PK', 1],
['UUID', 'd9ae48df-22cf-4ee2-9d47-0e16f48c8b0a'],
['Label', 'crystal17.basic-mock_crystal17@localhost'],
['Description', ''],
['Default plugin', 'crystal17.basic'],
['Type', 'remote'],
['Remote machine', 'localhost'],
['Remote absolute path', '//anaconda/envs/aiida-workshop/bin/mock_crystal17'],
['Prepend text', 'No prepend text'],
['Append text', 'No append text']]
An SinglefileData
node is
then set containing the main input file.
In:
SinglefileData = DataFactory('singlefile')
infile = SinglefileData(
file=os.path.join(TEST_FILES, 'crystal',
'mgo_sto3g_scf', 'INPUT'))
with infile.open() as handle:
print(handle.read())
MgO bulk
CRYSTAL
0 0 0
225
4.21
2
12 0. 0. 0.
8 0.5 0.5 0.5
END
12 3
1 0 3 2. 0.
1 1 3 8. 0.
1 1 3 2. 0.
8 2
1 0 3 2. 0.
1 1 3 6. 0.
99 0
END
SHRINK
8 8
END
Setting Up and Running the Calculation¶
See also
AiiDA documentation: Processes
A builder can be obtained from the Code
node, which will define all
the required input nodes and settings:
In:
builder = code.get_builder()
builder.metadata.options.withmpi = False
builder.metadata.options.resources = {
"num_machines": 1,
"num_mpiprocs_per_machine": 1}
builder.input_file = infile
display_json(builder)
{
"metadata": {
"options": {
"withmpi": false,
"resources": {
"num_machines": 1,
"num_mpiprocs_per_machine": 1
}
}
},
"code": [
"Remote code 'crystal17.basic-mock_crystal17@localhost' on localhost,",
"pk: 1, uuid: d9ae48df-22cf-4ee2-9d47-0e16f48c8b0a"
],
"input_file": [
"uuid: 05efe37e-4cd3-4d91-95a6-b4ba60c5de60 (unstored)"
]
}
In order to run the computation, the builder can be parsed to one of the
AiiDA run
(blocking execution) or submit
(non-blocking
execution) functions:
In:
result, calcnode = run_get_node(builder)
The process can be monitored on the command line:
In:
!verdi process list -a -l 1 -D desc
PK Created Process label Process State Process status
---- --------- ------------------- --------------- ----------------
85 19s ago CryBasicCalculation ⏹ Finished [0]
Total results: 1
Info: last time an entry changed state: 5s ago (at 11:59:54 on 2019-07-18)
Once the calculation is complete, a CalcJobNode
will be created, to
store the settings and outcome of the computation. Crucially, if the
computation has completed successfully, the exit_status
will be
0.
This can be assessed on the command line or with the python API.
In:
!verdi process show {calcnode.pk}
Property Value
------------- ------------------------------------
type CalcJobNode
pk 85
uuid bcdf898e-8e10-4178-954e-7bae251ea818
label
description
ctime 2019-07-18 11:59:40.311646+00:00
mtime 2019-07-18 11:59:54.376399+00:00
process state Finished
exit status 0
computer [1] localhost
Inputs PK Type
---------- ---- --------------
code 1 Code
input_file 84 SinglefileData
Outputs PK Type
------------- ---- -------------
remote_folder 86 RemoteData
results 88 Dict
retrieved 87 FolderData
structure 89 StructureData
symmetry 90 SymmetryData
In:
print(calcnode.is_finished_ok)
print(calcnode.process_state)
print(calcnode.exit_status)
True
ProcessState.FINISHED
0
If the calculation fails, there are three things that should be checked:
The calculation’s exit_message
The calculation’s log messages and scheduler output
The
results
output node (if available)
In:
print("Exit Message:", calcnode.exit_message)
from aiida.cmdline.utils.common import get_calcjob_report
print(get_calcjob_report(calcnode))
Exit Message: None
*** 85: None
*** (empty scheduler output file)
*** (empty scheduler errors file)
*** 0 LOG MESSAGES
In:
!verdi process report {calcnode.pk}
*** 85: None
*** (empty scheduler output file)
*** (empty scheduler errors file)
*** 0 LOG MESSAGES
Analysis of Outputs¶
The aiida.tools.visualization.graph.Graph
can be used to
visualise the calculations provenance graph:
In:
from aiida.tools.visualization import Graph
graph = Graph(graph_attr={'size': "6,8!", "rankdir": "LR"})
graph.add_node(calcnode)
graph.add_incoming(calcnode, annotate_links="both")
graph.add_outgoing(calcnode, annotate_links="both")
graph.graphviz
Out:
The retrieved
FolderData
output node contains the CRYSTAL17 main
output file.
In:
calcnode.outputs.retrieved.list_object_names()
Out:
['_scheduler-stderr.txt', '_scheduler-stdout.txt', 'main.out']
The results
Dict
output node contains key values extracted from
the CRYSTAL17 main output file.
In:
display_json(calcnode.outputs.results.attributes)
{
"units": {
"angle": "degrees",
"energy": "eV",
"length": "angstrom",
"conversion": "CODATA2014"
},
"energy": -7380.2216051903,
"errors": [],
"header": {
"crystal_version": 17,
"crystal_subversion": "1.0.1"
},
"volume": 18.65461525,
"warnings": [],
"calculation": {
"n_ao": 14,
"spin": false,
"type": "restricted closed shell",
"n_atoms": 2,
"n_shells": 5,
"n_symops": 48,
"n_core_el": 12,
"n_electrons": 20,
"n_kpoints_ibz": 29,
"n_kpoints_gilat": 29
},
"energy_units": "eV",
"parser_class": "CryMainParser",
"parser_errors": [],
"parser_version": "0.9.0b5",
"scf_iterations": 7,
"number_of_atoms": 2,
"parser_warnings": [
"no initial structure available, creating new kinds for atoms"
],
"parser_exceptions": [],
"number_of_assymetric": 2,
"execution_time_seconds": 3
}
The structure
StructureData
output node contains the final
structure, obtained from the CRYSTAL17 main output file.
In:
%matplotlib inline
import matplotlib.pyplot as plt
from ase.visualize.plot import plot_atoms
atoms = calcnode.outputs.structure.get_ase()
fig, ax = plt.subplots()
plot_atoms(atoms.repeat((4,4,4)),
ax, radii=0.8, show_unit_cell=True,
rotation=('45x,0y,0z'));
The symmetry
SymmetryData
output node contains the symmetry of
the final structure, obtained from the CRYSTAL17 main output file.
In:
print(calcnode.outputs.symmetry.attributes)
calcnode.outputs.symmet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