cvm package

Submodules

cvm.base module

class cvm.base.BaseCVM(meta: dict, *, series: List[dict] = None, experiment: dict = None)[source]

Bases: collections.defaultdict

CVM is a general CVM (Cluster Variation Method) calculation framework using NIM (Natural Iteration Method).

Parameters
  • meta (dict) – Meta information. It can be anything that will be used to describe this calculation set. This information will be passed over the whole calculation.

  • series (List[dict], optional) – Sample data contains raw energies, and other calculation needed parameters, by default None

  • experiment (dict, optional) – The experiment data, by default None

__call__(*labels, verbose: bool = False, early_stopping: float = 0.2, sample_paras: dict = {}, reset_paras: dict = {}, update_en_paras: dict = {}, process_paras: dict = {})[source]

Run CVM calculation as generator. Will yield calculation details on each step.

Parameters
  • labels (str) – If not None, only execute listed series samples.

  • verbose (bool, optional) – Set to True to show extra information when running calculations, by default False

  • sample_ite_paras (dict, optional) – The parameters will be passed to sample.ite and sample.__call__ method, by default empty.

  • reset_paras (dict, optional) – The parameters will be passed to self.reset method, by default empty.

  • update_en_paras (dict, optional) – The parameters will be passed to self.update_energy method, by default empty.

  • process_paras (dict, optional) – The parameters will be passed to self.process method, by default empty.

add_sample(sample: cvm.sample.Sample)[source]

Add sample data

Parameters

sample (Sample) – Instance of Sample.

classmethod from_input_set(path_of_set: str)[source]

Build a CVM instance from input set.

Parameters

path_of_set (str) – The path of input set dir.

Returns

New CVM instance.

Return type

BaseCVM

classmethod from_samples(meta: dict, *samples, experiment: dict = None)[source]

Build a CVM instance from series samples.

Parameters
  • meta (dict) – Meta information. It can be anything that will be used to describe this calculation set. This information will be passed over the whole calculation.

  • samples (Sample) – List of Series sample.

  • experiment (dict, optional) – The experiment data, by default None

Returns

New CVM instance.

Return type

BaseCVM

abstract process(**kwargs)[source]

The main loop to execute a NIM calculation step-by-step..

abstract reset(**kwargs)[source]

Reset all conditions for new calculation.

run(*labels, verbose: bool = False, early_stopping: float = 0.2, sample_paras: dict = {}, reset_paras: dict = {}, update_en_paras: dict = {}, process_paras: dict = {})[source]

Run CVM calculation.

Parameters
  • labels (str) – If not None, only execute listed series samples.

  • verbose (bool, optional) – Set to True to show extra information when running calculations, by default False

  • sample_ite_paras (dict, optional) – The parameters will be passed to sample.ite and sample.__call__ method, by default empty.

  • reset_paras (dict, optional) – The parameters will be passed to self.reset method, by default empty.

  • update_en_paras (dict, optional) – The parameters will be passed to self.update_energy method, by default empty.

  • process_paras (dict, optional) – The parameters will be passed to self.process method, by default empty.

abstract update_energy(e_ints, **kwargs)[source]

Update energies.

property results

Get calculated results.

Returns

Return type

results

cvm.normalizer module

class cvm.normalizer.Normalizer(energies: pandas.core.frame.DataFrame, clusters, targets)[source]

Bases: collections.defaultdict

property interaction_energies

cvm.results module

cvm.sample module

class cvm.sample.Sample(label: str, host: str, impurity: str, *, temperature: list = None, energies: pandas.core.frame.DataFrame = None, clusters: dict = None, mean: str = 'arithmetic', vibration: bool = True, skip: bool = False, x_1: float = 0.001, condition: float = 1e-07, r_0: Union[float, dict, str] = None, normalizer: Union[dict, cvm.normalizer.Normalizer] = None)[source]

Bases: collections.defaultdict

Sample is a object which store a group of configuration data for calculation

Parameters
  • label (str) – The Sample label.

  • host (str, optional) – The column name of host energies in energies.

  • host – The column name of impurity energies in energies.

  • temperature (list, optional) – Temperature steps follow the format [start, stop, # of steps]. By default None.

  • energies (pd.DataFrame, optional) – A pandas.DataFrame object contain raw energies. By default None.

  • clusters (dict, optional) – Set how to calculate interaction energy. By default None.

  • mean (str, optional) – Specific how to mix atom weights. Can be ‘arithmetic’, ‘harmonic’, and ‘geometric’. By default ‘arithmetic’.

  • vibration (bool, optional) – Specific whether or not to import the thermal vibration effect. By default True.

  • skip (bool, optional) – Set to true to skip this series sample. By default False.

  • x_1 (float, optional) – The initialization concentration of impurity. By default 0.001.

  • condition (float, optional) – Convergence condition. By default 1e-07.

  • r_0 (Union[float, dict, str], optional) – Set how to estimate r_0 from the given T and c. If local, r_0 will be calculated from each phase respectively. If constant, will ignore T and c. If dict, will do a parabolic curve fitting. By default None.

  • normalizer (Union[dict, Normalizer], optional) – Configuration of a Normalizer or an instance. If given, this will be used to normalize the long-range interaction energy. By default None.

__call__(*, T: float = None, r: [<class 'float'>, <class 'dict'>, <class 'str'>, None] = None, vibration: bool = None, energy_patch: Callable[[float, float], collections.namedtuple] = None, **kwargs)[source]

Get interaction energies at given T, and r.

Parameters
  • T (float) – Temperature.

  • r (float, dict, str, or None, optional) – Atomic distance. By default None.

  • vibration (bool) – Specific whether or not to import the thermal vibration effect.

  • energy_patch (Callable[[float, float], namedtuple], optional) – A patch that will be used to correct the returns of interaction energy. By default None.

Returns

namedtuple – Named tuple contains calculated interaction energies.

Return type

namedtuple

ite(*, temperature: list = None, k: int = 3, vibration: bool = None, r_0: [<class 'float'>, <class 'dict'>, <class 'str'>, None] = None, **kwargs)[source]

Iterate over each temperature

Parameters
  • temperature (list, optional) – Reset temperature steps, by default None

  • k (int) – Degree of the smoothing spline. Must be <= 5. Default is k=3, a cubic spline.

  • vibration (bool) – Specific whether or not to import the thermal vibration effect.

Yields
  • T (float) – Temperature at current step.

  • r_func (Callable[[float], float]) – A function receiving impurity concentration c and returns corresponding atomic distance r.

set_clusters(**val)[source]
set_energies(energies)[source]
set_normalizer(val)[source]
set_temperature(temp)[source]
property clusters
property energies
property normalizer
property temperatures

cvm.solution_limit module

cvm.solution_limit.percent(x, pos=0)[source]
cvm.solution_limit.process(opt)[source]

cvm.utils module

class cvm.utils.UnitConvert[source]

Bases: object

static ad2lc(d, n=4)[source]
static au2K(t)[source]
static eV2Kbar(p)[source]
static lc2ad(d, n=4)[source]
static ry2eV(t)[source]
cvm.utils.get_inp(path)[source]
cvm.utils.mixed_atomic_weight(formula: str, *, mean='arithmetic')[source]
cvm.utils.parse_input_set(path_of_set)[source]
cvm.utils.parse_formula(formula)[source]
Parameters

formula (str) – A string formula, e.g. Fe2O3, Li3Fe2(PO4)3

Returns

Composition with that formula.

Notes

In the case of Metallofullerene formula (e.g. Y3N@C80), the @ mark will be dropped and passed to parser.

cvm.utils.cvm_context(**kwargs)[source]

Set temp environment variable using with statement.

Examples

>>> import os
>>> with cvm_context(simple_print='True'):
>>>    print(os.getenv('simple_print'))
True
>>> print(os.getenv('simple_print'))
None
Parameters

kwargs (dict[str]) – Dict with string value.

cvm.utils.logspace(start: float, end: float, num: int) → numpy.ndarray[source]

Generate log scaled series.

Parameters
  • start (float) – Start point.

  • end (float.) – End point

  • num (int) – Steps.

Returns

series

Return type

np.ndarray

cvm.vibration module

class cvm.vibration.ClusterVibration(*, label: str, xs: list, ys: list, mass: float, num: int, morse_paras_bounds: list = None)[source]

Bases: object

Tools class for cluster vibration

Calculate phase energy using debye-sg model

Parameters
Raises

ValueErrorxs and ys must have same shape.

__call__(*, T: float = None, r: [<class 'float'>, <class 'str'>] = 'local', min_x: str = None)[source]

Get free energy.

Parameters
  • T (float, optional) – Temperature. If None, will set parameter vibration to False automatically.

  • r (float or str, optional) – Atomic distance, If local, will ues the default setting which be set when instancing. by default None.

  • min_x (str, optional) – By default None. If None, will ues the default setting which be set when instancing. If not None, function will returns equilibrium lattice constant as second result. The string can be ws or lattice.

debye_function(T: float, r: float = None, *, n: int = 3) → float[source]

Debye function.

Parameters
  • T (float) – Temperature.

  • r (float, optional) – Atomic distance, by default None

  • n (int, optional) – Dimssion, by default 3

Returns

Return type

float

debye_temperature(r: [<class 'float'>, <class 'str'>] = 'local') → float[source]

Debye temperature function.

Parameters

r (float, str, optional) – Atomic distance, by default None

Returns

Return type

float

morse_potential(r: float) → float[source]

Morse potential

Parameters

r (float) – Atomic distance

Returns

Potential energy.

Return type

float

property bulk_modulus

Estimated bulk modulus.

Returns

Return type

float

property c1

Morse potential parameter C1.

Returns

Return type

float

property c2

Morse potential parameter C2.

Returns

Return type

float

property equilibrium_lattice_cons

Equilibrium lattice constant.

Returns

Return type

float

property gamma_0
property lmd

Morse potential parameter lambda.

Returns

Return type

float

property r_0

Atomic distance at equilibrium status.

Returns

Return type

float

property x_0

Module contents