Core API

Entry

class qmpy.Entry(*args, **kwargs)

Base class for a database entry.

The core model for typical database entries. An Entry model represents an input structure to the database, and can be created from any input file. The Entry also ties together all of the associated Structures, Calculations, References, FormationEnergies, and other associated database entries.

Database fields: calculation, composition, dos, duplicate_of, duplicates, element_set, formationenergy, id, job, label, meta_data, natoms, ntypes, path, project_set, prototype, reference, species_set, structure, task

calculations

Dictionary of label:Calculation pairs.

chg

Attempts to load the charge density of the final calculation, if it is done. If not, returns False.

classmethod create(source, keywords=, []projects=, []**kwargs)

Create an Entry object from a provided input file.

Keywords:
keywords: list of keywords to associate with the entry. projects: list of project names to associate with the entry.
do(module, *args, **kwargs)

Looks for a computing script matching the first argument, and attempts to run it with itself as the first argument. Sends args and kwargs to the script. Should return a Calculation object, or list of Calculation objects.

Example: >>> e = Entry.objects.get(id=123) >>> e.do(‘relaxation’) <Calculation: 523 @ relaxation settings>

elements

List of Elements

energy

If the structure has been relaxed, returns the formation energy of the final relaxed structure. Otherwise, returns None.

errors

List of errors encountered in all calculations.

hold_objects

Return list of holds

holds

A note indicating a reason the entry should not be calculated

html

HTML formatted name

keyword_objects

Return list of keywords

keywords

Descriptive keyword for looking up entries

latex

LaTeX formatted name

mass

Return the mass of the entry, normalized to per atom.

move(path)

Moves all calculation files to the specified path.

name

Unformatted name

projects

List of Projects

red_comp

Composition dictionary, in reduced form.

reset()

Deletes all calculations, removes all associated structures - returns the entry to a pristine state.

save(*args, **kwargs)

Saves the Entry, as well as all associated objects.

space

Return the set of elements in the input structure.

Example: >>> e = Entry.create(“fe2o3/POSCAR”) # an input containing Fe2O3 >>> e.space set([“Fe”, “O”])

spec_comp

Composition dictionary, using species (element + oxidation state) instead of just the elements.

species

List of Species

total_energy

If the structure has been relaxed, returns the formation energy of the final relaxed structure. Otherwise, returns None.

unit_comp

Composition dictionary, normalized to 1 atom.

visualize(structure='source')

Attempts to open the input structure for visualization using VESTA

volume

If the entry has gone through relaxation, returns the relaxed volume. Otherwise, returns the input volume.

Structure

class qmpy.Structure(*args, **kwargs)

Structure model. Principal attributes are a lattice and basis set.

Database fields: atom_set, calculated, composition, delta_e, element_set, energy, energy_pa, entry, fit, id, label, magmom, magmom_pa, measured, meta_data, meta_stability, natoms, nsites, ntypes, prototype, reference, site, source, spacegroup, species_set, step, sxx, sxy, syy, syz, szx, szz, volume, volume_pa, x1, x2, x3, y1, y2, y3, z1, z2, z3

atom_types

List of atomic symbols, length equal to number of atoms.

atomic_numbers

List of atomic numbers, length equal to number of atoms.

cartesian_coords

Return atomic positions in cartesian coordinates.

cell

Lattice vectors, 3x3 numpy.ndarray.

comment_objects

Return list of comments

comp

Composition dictionary.

coords

numpy.ndarray of atom coordinates of shape (3, natoms).

copy()

Create a complete copy of the structure, with any primary keys removed, so it is not associated with the original.

elements

List of Elements

forces

numpy.ndarray of forces on atoms.

get_distance(atom1, atom2)

Return the shorted distance between two atoms in the structure.

get_sites(tol=0.1)

From self.atoms, creates a list of Sites. Atoms which are closer than tol from one another are considered on the same site.

get_volume()

Calculates the volume from the triple product of self.cell

group_atoms_by_symmetry()

Sort self.atoms according to the site they occupy.

inv

Precalculates the inverse of the lattice, for faster conversion between cartesian and direct coordinates.

joggle_atoms(distance=0.01, in_place=True)

Randomly displace all atoms in each direction by a distance up to +/- the distance keyword argument.

Optional keyword arguments:
distance : Range within all internal coordinates are
displaced. Default=1e-2
in_place : If True, returns an ndarray of the applied
translations. If False, returns (Structure, translations).

Examples: >>> s = io.read(‘POSCAR’) >>> s2, trans = s.joggle_atoms(in_place=False) >>> trans = s.joggle_atoms(1e-1) >>> trans = s.joggle_atoms(distance=1e-1)

keyword_objects

Return list of keywords

lat_param_dict

Dictionary of lattice parameters.

lat_params

Tuple of lattice parameters (a, b, c, alpha, beta, gamma).

magmoms

numpy.ndarray of magnetic moments of shape (natoms,).

make_conventional()

Uses spglib to convert to the conventional cell.

make_primitive()

Uses spglib to convert to the primitive cell.

Note: does not handle partial occupancy. If the cell is partially occupied, it is returned as is.

metrical_matrix

np.dot(self.cell.T, self.cell)

name

Unformatted name.

recenter(atom, in_place=True)

Translate the internal coordinates to center the specified atom. Atom can be an actual Atom from the Structure.atoms list, or can be identified by index.

Optional keyword arguments:
in_place : If False, return a new Structure with the
transformation applied.

Examples: >>> s = io.read(‘POSCAR’) >>> s.recenter(s[2]) >>> s2 = s.recenter(s[0], in_place=False) >>> s2.recenter(2) >>> s == s2 True

reciprocal_lattice

Reciprocal lattice of the structure.

reduce(tol=1e-05, limit=1000, in_place=True)

Get the transformation matrix from unit to reduced cell Acta. Cryst. (1976) A32, 297 Acta. Cryst. (2003) A60, 1

Optional keyword arguments:
tol : eps_rel in Acta. Cryst. 2003 above. Similar to
tolerance for floating point comparisons. Default=1e-5.
limit : maximum number of loops through the algorithm.
Default=1000.
in_place : change the species of the current Structure or
return a new one. If True, the transformation matrix is returned. If False, (Structure, transformation_matrix) is returned.

Examples: >>> s = io.read(‘POSCAR’) >>> s.reduce() >>> s.reduce(in_place=False, get_transform=False)

set_magnetism(type, scheme='primitive')

Assigns magnetic moments to all atoms in accordance with the specified magnetism scheme.

Schemes:

Keyword Description
None all magnetic moments = None
“ferro” atoms with partially filled d and f shells are assigned a magnetic moment of 5 mu_b
“anti” finds a highly ordererd arrangement arrangement of up and down spins. If only 1 magnetic atom is found a ferromagnetic arrangment is used. raises NotImplementedError
set_natoms(n)

Set self.atoms to n blank Atoms.

set_volume(value)

Rescales the unit cell to the specified volume, keeping the direction and relative magnitudes of all lattice vectors the same.

site_coords

numpy.ndarray of site coordinates of shape (3, nsites).

site_labels

Labels for all sites. For sites with single occupancy returns the atomic symbol, for sites with multiple occupancies returns “(A,B)”.

spec_comp

Species composition dictionary.

species

List of species

species_types

List of species, length equal to number of atoms.

stresses

Calculated stresses, a numpy.ndarray of shape (6,)

substitute(replace, rescale=True, in_place=False, **kwargs)

Replace atoms, as specified in a dict of pairs.

Optional keyword arguments:
  • rescale: rescale the volume of the final structure based on the per atom volume of the new composition.
  • in_place: change the species of the current Structure or return a new one.

Example: >>> s = io.read(‘POSCAR-Fe2O3’) >>> s2 = s.substitute({‘Fe’:’Ni’, ‘O’:’F’} rescale=True) >>> s2.substitute({‘Ni’:’Co’}, in_place=True, rescale=False)

symmetrize()

Analyze the symmetry of the structure. Uses spglib to find the symmetry.

symmetrize sets:
  • spacegroup -> Spacegroup
  • uniq_sites -> list of unique Sites
  • orbits -> lists of equivalent Atoms
  • for each atom: atom.wyckoff -> WyckoffSite
  • for each site: site.multiplicity -> int
transform(transform, in_place=True)

Apply lattice transform to the structure. Accepts transformations of shape (3,) and (3,3).

Optional keyword arguments:
in_place : If False, return a new Structure with the
transformation applied.

Examples: >>> s = io.read(‘POSCAR’) >>> s.transform([2,2,2]) # 2x2x2 supercell >>> s.transform([[0,1,0],[1,0,0],[0,0,1]]) # swap axis 1 for 2 >>> s2 = s.transform([2,2,2], in_place=False)

translate(cv, cartesian=True, in_place=True)

Shifts the contents of the structure by a vector.

Optional keyword arguments:
cartesian : If True, translation vector is taken to be
cartesian coordinates. If False, translation vector is taken to be in fractional coordinates. Default=True
in_place : If False, return a new Structure with the
transformation applied.

Examples: >>> s = io.read(‘POSCAR’) >>> s.translate([1,2,3]) >>> s.translate([0.5,0.5, 0.5], cartesian=False) >>> s2 = s.translate([-1,2,1], in_place=False)

unit_comp

Composition dict, where sum(self.unit_comp.values()) == 1

Atom

class qmpy.Atom(*args, **kwargs)

Model for an Atom.

Database fields: charge, direct, element, fx, fy, fz, id, magmom, occupancy, ox, site, structure, volume, wyckoff, x, y, z

copy()

Creates an exact copy of the atom, only without the matching primary key.

Example: >>> a = Atom.get(‘Fe’, [0,0,0]) >>> a.save() >>> a.id 1 >>> a.copy() >>> a <Atom: Fe @ [0.000, 0.000, 0.000]> >>> a.id None

classmethod create(element, coord, **kwargs)

Creates a new Atom object.

Arguments:
element (str or Element): Specifies the element of the Atom.

coord (iterable of floats): Specifies the coordinate of the Atom.

Keyword Arguments:
direct (bool): True if coord contains fractional coordinates, False if coord
contains cartesian coordinates.

forces (floats): Specifies the forces on the atom. magmom (float): The magnitude of the magnetic moment on the atom. charge (float): The charge on the Atom. volume (float): The atomic volume of the atom (Angstroms^3).

Examples: >>> Atom.create(‘Fe’, [0,0,0]) >>> Atom.create(‘Ni’, [0.5, 0.5, 0.5], ox=2, magmom=5, >>> forces=[0.2, 0.2, 0.2], >>> volume=101, charge=1.8, >>> occupancy=1)

is_on(site, tol=1e-05)

Tests whether or not the Atom is on the specified Site.

Examples: >>> a = Atom.create(‘Fe’, [0,0,0]) >>> s = a.as_site() >>> a2 = Atom.create(‘Ni’, [0,0,0]) >>> a2.is_on(s) True

Site

class qmpy.Site(*args, **kwargs)

A lattice site.

Database fields: atom_set, id, structure, wyckoff, x, y, z

A site can be occupied by one Atom, many Atoms or no Atoms.

add_atom(atom, tol=0.001)

Adds Atom to Site.atoms.

Notes:

Tests whether the atom belongs to different Structure and if it is within tol of the Site.

If the Site being assigned to doens’t have a coordinate, it is assigned the coordinate of atom.

Arguments:
atom (Atom): Atom to add to the structure.
Keyword Arguments:
tol (float): Distance between atom and the Site for the Atom to be
assigned to the Site. Raises a SiteError if the distance is greater than tol.
Raises:
SiteError: If atom is more than tol from the Site.

Examples: >>> s = Site.create([0,0,0]) >>> a = Atom.create(‘Fe’, [0,0,0]) >>> s.add_atom(a) >>> s2 = Site() >>> s2.add_atom(a)

atoms

List of Atoms on the Site.

cart_coord
Returns:
length 3 array of floats. The positions of the Site in cartesian coordinates.
Raises:
SiteError: If the Site coordinates are direct, and the Site is not associated with a structure, cartesian coordinates cannot be determined, so a SiteError is raised.
comp

Composition dictionary of the Site.

Returns:
dict: of (element, occupancy) pairs.

Examples: >>> a1 = Atom(‘Fe’, [0,0,0], occupancy=0.2) >>> a2 = Atom(‘Ni’, [0,0,0], occupancy=0.8) >>> s = Site.from_atoms([a1,a2]) >>> s.comp {‘Fe’:0.2, ‘Ni’:0.8}

coord

[Site.x, Site.y, Site.z]

classmethod create(coord=None, comp=None)

Constructs a Site from a coordinate.

Note:
The Site is created without any Atoms occupying it.
Keyword Arguments:
coord (length 3 iterable): Assigns the x, y, and z coordinates of
the Site.
comp (dict, string, or qmpy.Element): Composition dictionary.
Flexible about input forms. Options include: <Element: Fe>, ‘Fe’, {“Fe”:0.5, “Co”:0.5}, and {<Element: Ni>:0.5, <Element: Co>:0.5}.

Examples: >>> s = Site.create([0.5,0.5,0.5])

classmethod from_atoms(atoms, tol=0.0001)

Constructs a Site from an iterable of Atoms.

Notes:

Site.coord is set as the average coord of all assigned Atoms.

Checks that the Atoms are close together. If the Atoms are further apart than tol, raises a SiteError

Arguments:
atoms (iterable of Atom): List of Atoms to occupy the Site.
Keyword Arguments:
tol (float): Atoms must be within tol of each other to be assigned to the same Site. Defaults to 1e-4.

Examples: >>> a1 = Atom.create(‘Fe’, [0,0,0]) >>> a2 = Atom.create(‘Ni’, [1e-5, -1e-5, 0]) >>> s = Site.from_atoms([a1,a1])

full(tol=0.001)

Evaluates whether the Site is fully occupied.

Returns:
bool: True if the sum of the occupancies of all atoms on the site is within tol of 1.
label()

Assigns a human friendly label for the Site, based on its atomic composition. If singly occupied, returns the symbol of the atom on the site. If multiply occupied, returns a comma seperated string

Examples: >>> s = Site.create({

magmom()

Calculates the composition weighted average magnetic moment of the atoms on the Site.

Returns:
float or None
occupancy()

Calculates the total occupancy of the site.

Returns:
float or None
ox

Calculates the composition weighted average oxidation state of the atoms on the Site.

Returns:
float or None

Calculation

class qmpy.Calculation(*args, **kwargs)

Base class for storing a VASP calculation.

Database fields: attempt, band_gap, composition, configuration, converged, dos, element_set, energy, energy_pa, entry, fit, formationenergy, hubbard_set, id, input, irreducible_kpoints, label, magmom, magmom_pa, meta_data, natoms, nsteps, output, path, potential_set, runtime, settings

error_objects

Return list of errors

get_outcar()

Sets the calculations outcar attribute to a list of lines from the outcar.

Example: >>> calc = Calculation.read(‘calculation_path’) >>> print calc.outcar None >>> calc.get_outcar() >>> len(calc.outcar) 12345L

static read(path)

Reads the outcar specified by the objects path. Populates input field values, as well as outputs, in addition to finding errors and confirming convergence.

Example: >>> calc = Calculation.read(‘/path/to/calculation’)

read_charges()

Reads and returns VASP’s calculated charges for each atom. Returns the RAW charge, not NET charge.

Example: >>> calc = Calculation.read(‘path_to_calculation’) >>> calc.read_charges()

read_elements()

Reads the elements of the atoms in the structure. Returned as a list of atoms of shape (natoms,).

Example: >>> calc = Calculation.read(‘path_to_calculation’) >>> calc.read_elements() [‘Fe’, ‘Fe’, ‘O’, ‘O’, ‘O’]

read_energies()

Returns a numpy.ndarray of energies over all ionic steps.

Example: >>> calc = Calculation.read(‘calculation_path’) >>> calc.read_energies() array([-12.415236, -12.416596, -12.416927])

read_lattice_vectors()

Reads and returns a numpy ndarray of lattice vectors for every ionic step of the calculation.

Example: >>> calc = Calculation.read(‘path_to_calculation’) >>> calc.read_lattice_vectors() array([[[ 4.17458823, 0. , 0. ],

[-2.08729412, 3.61529939, 0. ], [ 0. , 0. , 5.20720757]],
[[ 4.17458823, 0. , 0. ],
[-2.08729412, 3.61529939, 0. ], [ 0. , 0. , 5.20720757]],
[[ 4.15950113, 0. , 0. ],
[-2.07975057, 3.60223358, 0. ], [ 0. , 0. , 5.18670694]],
[[ 4.16254664, 0. , 0. ],
[-2.08127332, 3.60487107, 0. ], [ 0. , 0. , 5.18394359]]])
read_n_ionic()

Reads the number of ionic steps, and assigns the value to nsteps.

read_natoms()

Reads the number of atoms, and assigns the value to natoms.

warning_objects

Return list of warnings

Task

class qmpy.Task(*args, **kwargs)

Model for a Task to be done. A Task consists of a module, which is the name of a computing script.

Database fields: created, entry, finished, id, job, kwargs, module, priority, project_set, state

Task codes:

Code Description
-2 being held
-1 encountered error
0 ready to run
1 jobs running
2 completed
complete()

Sets the Task state to 2 and populates the finished field.

errors

List of errors encountered by related calculations.

get_jobs(project=None, allocation=None, account=None, host=None)

Calls the task’s entry’s “do” method, with first argument as the tasks module, and subsequent arguments as the args list. If there is nothing left to do, returns an empty sequence. Cases:

given a project given an allocation
jobs

List of jobs related to the task.

projects

List of related projects.

Job

class qmpy.Job(*args, **kwargs)

Base class for job submitted to a compute cluster.

Database fields: account, allocation, created, entry, finished, id, ncpus, path, qid, run_path, state, task, walltime

Job codes

Code Description
-1 encountered error
0 ready to submit
1 currently running
2 completed

Table Of Contents

Previous topic

Getting Started

This Page