Example 06: Running calphy from jupyter notebooks#

In this example, calphy will be used as a library to run Example 01 directly from a jupyter notebook. Please check example 01 before completing this example. We start by import a function to read the input file.

[1]:
from calphy.input import read_inputfile
[2]:
options = read_inputfile("input.1.yaml")

We can check the number of calculations present

[3]:
len(options)
[3]:
1

The individual methods that are required to run the calculation can be imported from the queuekernel module.

[4]:
import calphy.queuekernel as cq

First, we set up a class which prepares everything for the calculation. It takes one object from options as the argument.

[5]:
job = cq.setup_calculation(options[0])
[6]:
job
[6]:
Calculation(composition_scaling=CompositionScaling(output_chemical_composition=None, restrictions=[]), md=MD(timestep=0.001, n_small_steps=10000, n_every_steps=10, n_repeat_steps=10, n_cycles=100, thermostat_damping=[0.1, 0.1], barostat_damping=[0.1, 0.1], cmdargs=None, init_commands=None), nose_hoover=NoseHoover(thermostat_damping=0.1, barostat_damping=0.1), berendsen=Berendsen(thermostat_damping=100.0, barostat_damping=100.0), queue=Queue(scheduler='local', cores=4, jobname='calphy', walltime=None, queuename=None, memory='3GB', commands=['conda activate calphy'], options=None, modules=None), tolerance=Tolerance(lattice_constant=0.0002, spring_constant=0.1, solid_fraction=0.7, liquid_fraction=0.05, pressure=0.5), melting_temperature=MeltingTemperature(guess=None, step=200, attempts=5), element=['Fe'], n_elements=1, mass=[55.845], mode='fe', lattice='/mnt/c/Users/menon/Documents/winrepos/projects-calphy/calphy/examples/example_06/input.conf.data', file_format='lammps-data', pressure=0.0, temperature=100.0, melting_cycle=True, pair_style=['eam'], pair_coeff=['* * /mnt/c/Users/menon/Documents/winrepos/projects-calphy/calphy/examples/potentials/Fe.eam'], potential_file=None, fix_potential_path=True, reference_phase='solid', lattice_constant=2.8842, repeat=[5, 5, 5], script_mode=False, lammps_executable=None, mpi_executable=None, npt=True, n_equilibration_steps=10000, n_switching_steps=25000, n_print_steps=0, n_iterations=1, equilibration_control='nose-hoover', folder_prefix=None, spring_constants=None)

These properties can also be accessed individually.

[9]:
job.calc.temperature, job.calc.pressure
[9]:
(100.0, 0.0)

Now finally the calculation can be run

[8]:
job = cq.run_calculation(job)

The results can be obtained through the report variable

[10]:
job.report
[10]:
{'input': {'temperature': 100,
  'pressure': 0.0,
  'lattice': 'BCC',
  'element': 'Fe',
  'concentration': '1.0'},
 'average': {'vol_atom': 11.994275525217516,
  'spring_constant': '3.03',
  'density': 0.08337660890608233},
 'results': {'free_energy': -4.263538447248216,
  'error': 0.0,
  'reference_system': 0.01385313501678647,
  'work': -4.277391582265002,
  'pv': 0.0,
  'unit': 'eV/atom'}}

or individually as class attributes

[11]:
job.fe, job.w, job.pv
[11]:
(-4.263538447248216, -4.277391582265002, 0)

If more than one calculation is present, they should be run individually.