Functional class and attributes

class pylada.dftcrystal.functional.Functional(program=None, copy=None, **kwargs)[source]

Bases: object

Wrapper for the CRYSTAL program.

This object provides a pythonic interface to the CRYSTAL program. It is modelled loosely after CRYSTAL‘s input:

  • The OPTGEOM keyword of the first code block can be accessed through the optgeom attribute:

    # enable geometry optimization
    functional.optgeom.enabled = True
    # change some of the keywords
    functional.optgeom.maxcycle = True
    

    Geometry optimization must be explicitly enabled, as is done in the first line above.

  • The interface to the second block of input (basis-functions) can be accessed through the basis attribute. It allows to set the basis set itself, as well as keywords specific to the basis set:

    functional.basis['H'] = [Shell('s', a0=(15.0, 1.0), a1=(8.0, 1.0)), ...]
    functional.basis.ghosts = [1, 4, 6], False
    
  • The third input block (Hamiltonian and miscellaneous) can be accessed directly through the functional, or, alternatively, via the scf attribute.

    functional.scf.dft.b3lyp = True
    functional.dft.b3lyp = True
    
    functional.tolinteg = [8] * 4 + [14]
    

    The first two lines are exactly equivalent. The third line could also be written as functional.scf.tolinteg = ....

Following the pattern of CRYSTAL‘s input, the parameters are separated into sub-blocs:

Extract = <class 'pylada.dftcrystal.extract.Extract'>

Extraction class.

__call__(structure, outdir=None, workdir=None, comm=None, overwrite=False, test=False, **kwargs)[source]

Performs a CRYSTAL calculation

If successfull results (see extract.Extract.success) already exist in outdir, calculations are not repeated. Instead, an extraction object for the stored results are given.

Parameters:
  • structureStructure structure to compute.
  • outdir – Output directory where the results should be stored. This directory will be checked for restart status, eg whether calculations already exist. If None, then results are stored in current working directory.
  • comm – Holds arguments for executing CRYSTAL externally.
  • overwrite – If True, will overwrite pre-existing results. If False, will check whether a successfull calculation exists. If one does, then does not execute.
  • test – If True, TEST is inserted at the very end of the run. This makes it easier to check that the input is correct.
  • kwargs – Any attribute of the VASP instance can be overidden for the duration of this call by passing it as keyword argument.
Returns:

Yields an extractor object if a prior successful run exists. Otherwise, yields a tuple object for executing an external program.

Note :

This functor is stateless as long as self and structure can be deepcopied correctly.

Raises:
  • ExternalRunFailed – when computations do not complete.
  • IOError – when outdir exists but is not a directory.

This version performs a blocking call to the CRYSTAL program. It works as follows:

>>> from pylada.dftcrystal import Crystal, Functional
>>> # create an object
>>> functional = Functional()
>>> # initialize it
>>> functional.basis['H'] = ...
...
>>> # call the functional on a Crystal structure.
>>> result = functional(crystal, outdir='ther', comm=comm)
>>> print result.total_energy
-666 eV
iter(structure, outdir=None, **kwargs)[source]

Performs a CRYSTAL calculation

If successfull results (see extract.Extract.success) already exist in outdir, calculations are not repeated. Instead, an extraction object for the stored results are given.

Parameters:
  • structureStructure structure to compute.
  • outdir – Output directory where the results should be stored. This directory will be checked for restart status, eg whether calculations already exist. If None, then results are stored in current working directory.
  • comm – Holds arguments for executing CRYSTAL externally.
  • overwrite – If True, will overwrite pre-existing results. If False, will check whether a successfull calculation exists. If one does, then does not execute.
  • test – If True, TEST is inserted at the very end of the run. This makes it easier to check that the input is correct.
  • kwargs – Any attribute of the VASP instance can be overidden for the duration of this call by passing it as keyword argument.
Returns:

Yields an extractor object if a prior successful run exists. Otherwise, yields a tuple object for executing an external program.

Note :

This functor is stateless as long as self and structure can be deepcopied correctly.

Raises:
  • ExternalRunFailed – when computations do not complete.
  • IOError – when outdir exists but is not a directory.

This version does not perform the actual call to the CRYSTAL. Rather, it is a generator which yields two types of objects:

The last object yielded should be an extraction object refering to the final calculation. In practice, iter() is used as follows:

for process in functional.iter(crystal, ...):
  # check whether the generator yielded a process or not
  if hasattr(process, 'success'):
    # This is an extraction object
    # Do something
  else:
    # This is a process
    # call it somehow
    process.start(comm)
    process.wait()
print process.some_result # last process should be an extractor
add_keyword(name, value=None)[source]

Passes on to scf

optgeom

Geometry relaxation parameters.

This is an instance of OptGeom. Once enabled with

>>> functional.optgeom.enable = True

it will print out the geometry subblock into the input. It controls the structural relaxation:

>>> functional.optgeom.intredun = True
>>> functional.optgeom.maxcycle = 10

See also

OptGeom, Relax

basis
dft

It is an instance of Dft. Parameters from CRYSTAL‘s sub-block can be set here, for instance as:

>>> functional.dft.b3lyp = True
basis = None

Holds definition of basis functions – block 2.

kpoint_blocking(structure, nprocs, nkpoints=None, cmplxfac=None)[source]

Infers the number of procs per kpoint.

This function is helpfull in checking whether MPPcrystal will run correcly or not. It returns a list consisting of the number of procs per k-point. It is a list since CRYSTAL may assign some k-points with more processors than others, in order to maximize the number of processors used. However, this approach fails when a k-point is assigned a prime number of processors, because of some bug somewhere (see comment in k_space_MPP.f90: asssing_k_to_proc in CRYSTAL code). Unfortunately, MPPCrystal does not recover well from this problem.

mpp_compatible_procs(structure, multipleof=1, dof=20, cmplxfac=None)[source]

Returns list of MPP compatible processor counts.

Processor counts are compatible if:

  • \(N_p < N_{AO} * N_k * N_s // dof\)

  • \(N_p % multipleof == 0\)

  • the number of processors per k-point is never prime

    Where:

    • \(N_p\) is the number of cores
    • \(N_k\) is the number of irreducible kpoints
  • \(N_s\) is the number of spins

  • \(N_{AO}\) is the number of atomic orbitals

The last condition is somewhat more complex and depends upon the total number of kpoints, the number of k-points at the Brillouin zone edge, and the particular way CRYSTAL assigns procs for each k-point. This decomposition is computed in kpoint_blocking().

Parameters:
  • structure – Crystal structure for which to run the code.
  • multipleof (int) – Pars down results to multiple of this number (eg cores per node).
  • dof (int) – Minimum degrees of freedom per processor.
nbelectrons(structure)[source]

Number of electrons per formula unit.

optgeom = None

Holds definition of geometry optimization – part of block 1.

program = None

Path to crystal program.

If this attribute is None, then crystal_program is used.

restart = None

Place holder.

scf = None

Holds scf/electronic keywords – block 3.

test_basis(structure, **kwargs)[source]

Returns output of test basis run.

test_hamiltonian(structure, **kwargs)[source]

Returns output of test basis run.

title = None

Title of the calculation.

Overriden by the name of the input structure, if it exists.

Previous topic

CRYSTAL wrapper module

Next topic

Geometry optimization block

This Page