Source code for pysic.interactions.compound

#! /usr/bin/env python

from pysic.core import *
from pysic.utility.error import InvalidPotentialError
from pysic.interactions.local import Potential, ProductPotential
import copy

[docs]class CompoundPotential(Potential): """Class representing an interaction constructed of several :class:`~pysic.interactions.local.Potential` and :class:`~pysic.interactions.local.ProductPotential` objects. This class implements the framework for wrapping complicated potentials as Python objects. The class itself implements an empty potential. To utilize the compound potential for real calculations, subclasses should be used for defining the actual contents of the potential. Parameters: n_targets: integer number of targets the potential acts on n_params: integer number of parameters needed for describing the potential symbols: list of string the chemical symbols (elements) on which the potential acts tags: integer atoms with specific tags on which the potential acts indices: list of integers atoms with specific indices on which the potential acts parameters: list of doubles a list of parameters for characterizing the potential; their meaning depends on the type of potential cutoff: double the maximum atomic separation at which the potential is applied cutoff_margin: double the margin in which the potential is smoothly truncated to zero """ def __init__(self, n_targets, n_params, symbols=None, tags=None, indices=None, parameters=None, cutoff=0.0, cutoff_margin=0.0): self.n_targets = n_targets self.n_params = n_params self.symbols = None self.tags = None self.indices = None self.cutoff = cutoff self.cutoff_margin = 0.0 self.set_cutoff_margin(cutoff_margin) self.set_symbols(symbols) self.set_tags(tags) self.set_indices(indices) self.potential_type = None self.names_of_params = ["anonymous"]*n_params self.description_of_params = ["description missing"]*n_params self.description = "This compound potential has no description." self.pieces = [] def __eq__(self,other): try: if self.potential_type != other.potential_type: return False if self.symbols != other.symbols: return False if self.tags != other.tags: return False if self.indices != other.indices: return False if self.parameters != other.parameters: return False if self.cutoff != other.cutoff: return False if len(self.pieces) != len(other.pieces): return False for p1, p2 in zip(self.pieces, other.pieces): if(p1 != p2): return False except: return False return True def __ne__(self,other): return not self.__eq__(other)
[docs] def get_number_of_parameters(self): return self.n_params
[docs] def set_potential_type(self,type): self.potential_type = type
[docs] def get_elements(self): """Returns the elemental potentials this compund potential consists of. """ return self.pieces
[docs] def build(self,calculator): """Constructs the potential for the calculator as a collection of elemental potentials. Parameters: calculator: :class:`~pysic.calculator.Pysic` object the Pysic calculator to which the potential is added """ for potential in self.pieces: calculator.add_potential(potential)
[docs] def remove(self,calculator): """Constructs the potential for the calculator as a collection of elemental potentials. Parameters: calculator: :class:`~pysic.calculator.Pysic` object the Pysic calculator from which the potential is removed """ for pot in self.pieces: calculator.remove(pot)
[docs] def define_elements(self): self.pieces = [] # !!!: implement describe()