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 a main.d12 file containing the EXTERNAL keyword.

Initial Setup

To run a computation, first ensure AiiDA is running:

In:
!verdi status
profile:     On profile test_v1_1
repository:  /Users/cjs14/GitHub/aiida-crystal17/databases/aiida/test_v1_1
postgres:    Connected to cjs14@None:5432
rabbitmq:    Connected to amqp://127.0.0.1?heartbeat=600
daemon:      Daemon is running as PID 27187 since 2019-04-20 13:47:33

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 .gui (fort.34) 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
              10:  The process returned an invalid output
              11:  The process did not register a required output
             130:  The retrieved folder data node could not be accessed.
             140:  The main output file was not found
             200:  The main crystal output file flagged an error
             210:  An error was flagged trying to parse the main crystal output file
             220:  Inconsistency in the input and output symmetry
             230:  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:
'fes_db_1b3'
In:
import os
from aiida_crystal17.common import display_json
from aiida_crystal17.tests import TEST_DIR
from aiida.orm import Code
from aiida.engine import run_get_node
from aiida.plugins import DataFactory

Input Creation

See also

AiiDA documentation: Setup a code

CRYSTAL17 Manual

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_runcry17')
code.get_full_text_info()
Out:
[['PK', 912],
 ['UUID', '3f7b0845-e236-4684-94a5-5d52a593bccf'],
 ['Label', 'crystal17.basic-mock_runcry17@localhost'],
 ['Description', ''],
 ['Default plugin', 'crystal17.basic'],
 ['Type', 'remote'],
 ['Remote machine', 'localhost'],
 ['Remote absolute path', '//anaconda/envs/aiida-workshop/bin/mock_runcry17'],
 ['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_DIR, "input_files",
                          'mgo_sto3g_scf.crystal.d12'))
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_runcry17@localhost' on localhost,",
    "pk: 912, uuid: 3f7b0845-e236-4684-94a5-5d52a593bccf"
  ],
  "input_file": [
    "uuid: e13d5efb-e9b8-4bb8-b328-5ae98f75d7a3 (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 -p 1
  PK  Created    State           Process label        Process status
----  ---------  --------------  -------------------  ----------------
 387  13m ago    ⏹ Finished [0]  CryBasicCalculation

Total results: 1

Info: last time an entry changed state: 13m ago (at 12:48:36 on 2019-04-20)

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             387
uuid           08378a58-cf13-4e7c-921e-ea82d6820f32
label
description
ctime          2019-04-20 12:48:24.408128+00:00
mtime          2019-04-20 12:48:36.537236+00:00
process state  Finished
exit status    0
computer       [1] localhost

Inputs        PK  Type
----------  ----  --------------
code           7  Code
input_file   386  SinglefileData

Outputs          PK  Type
-------------  ----  -------------
remote_folder   388  RemoteData
results         390  Dict
retrieved       389  FolderData
structure       391  StructureData
symmetry        392  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:

  1. The calculation’s exit_message
  2. The calculation’s log messages and scheduler output
  3. 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
*** 387: None
*** Scheduler output:
running mock runcry17 for input arg: main
*** (empty scheduler errors file)
*** 0 LOG MESSAGES
In:
!verdi process report {calcnode.pk}
*** 387: None
*** Scheduler output:
running mock runcry17 for input arg: main
*** (empty scheduler errors file)
*** 0 LOG MESSAGES

Analysis of Outputs

The aiida_crystal17.graph.Graph can be used to visualise the calculations provenance graph:

In:
from aiida_crystal17.graph 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:
output_33_0

crystal17.basic calculation provenance graph.

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)
{
  "volume": 18.65461525,
  "number_of_assymetric": 2,
  "number_of_atoms": 2,
  "energy_units": "eV",
  "energy": -7380.22160519032,
  "scf_iterations": 7,
  "calculation_type": "restricted closed shell",
  "calculation_spin": false,
  "wall_time_seconds": 3,
  "warnings": [],
  "errors": [],
  "parser_warnings": [
    "no initial structure available, creating new kinds for atoms"
  ],
  "parser_errors": [],
  "ejplugins_version": "0.11.1",
  "parser_class": "CryMainParser",
  "parser_version": "0.4.0"
}

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'));
output_39_0

Structure visualisation, using ASE and Matplotlib.

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.symmetry.data.operations
{'num_symops': 48, 'hall_number': None, 'basis': 'fractional'}
Out:
[[1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
 [0.0, 1.0, 0.0, 1.0, 0.0, 0.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0],
 [-1.0, -1.0, -1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0],
 [0.0, 0.0, 1.0, -1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
 [0.0, 0.0, 1.0, 1.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