pyPRISM.core.PairTable module¶
-
class
pyPRISM.core.PairTable.
PairTable
(types, name, symmetric=True)[source]¶ Bases:
pyPRISM.core.Table.Table
Container for data that is keyed by pairs of types
Description
Since PRISM is a theory based in pair-correlation functions, it follows that many of the necessary parameters of the theory are specified between the pairs of types. This goal of this container is to make setting, getting, and checking these data easy.
Setter/getter methods have been set up to set groups of types simultaneously. This allows for the rapid construction of datasets where many of the parameters are repeated. This class also automatically assumes pair-reversibility and handles the setting of unlike pairs automatically i.e. A-B and B-A are set at the same time.
Note that, unlike the
pyPRISM.core.MatrixArray
, this container is not meant to be used for mathematics. The benefit of this is that, for each type, it can contain any arbitrary number, string, or Python object.See the example below and the pyPRISM Internals section of the Tutorial for more information.
Example
import pyPRISM PT = pyPRISM.PairTable(['A','B','C'],name='potential') # Set the 'A-A' pair PT['A','A'] = 'Lennard-Jones' # Set the 'B-A', 'A-B', 'B-B', 'B-C', and 'C-B' pairs PT['B',['A','B','C'] ] = 'Weeks-Chandler-Andersen' # Set the 'C-A', 'A-C', 'C-C' pairs PT['C',['A','C'] ] = 'Exponential' for i,t,v in PT.iterpairs(): print('{}) {} for pair {}-{} is {}'.format(i,VT.name,t[0],t[1],v)) # The above loop prints the following: # (0, 0)) potential for pair A-A is Lennard-Jones # (0, 1)) potential for pair A-B is Weeks-Chandler-Andersen # (0, 2)) potential for pair A-C is Exponential # (1, 1)) potential for pair B-B is Weeks-Chandler-Andersen # (1, 2)) potential for pair B-C is Weeks-Chandler-Andersen # (2, 2)) potential for pair C-C is Exponential for i,t,v in PT.iterpairs(full=True): print('{}) {} for pair {}-{} is {}'.format(i,VT.name,t[0],t[1],v)) # The above loop prints the following: # (0, 0)) potential for pair A-A is Lennard-Jones # (0, 1)) potential for pair A-B is Weeks-Chandler-Andersen # (0, 2)) potential for pair A-C is Exponential # (1, 0)) potential for pair B-A is Weeks-Chandler-Andersen # (1, 1)) potential for pair B-B is Weeks-Chandler-Andersen # (1, 2)) potential for pair B-C is Weeks-Chandler-Andersen # (2, 0)) potential for pair C-A is Exponential # (2, 1)) potential for pair C-B is Weeks-Chandler-Andersen # (2, 2)) potential for pair C-C is Exponential
-
__init__
(types, name, symmetric=True)[source]¶ Constructor
Parameters: - types (list) – Lists of the types that will be used to key the PairTable. The length of this list should be equal to the rank of the PRISM problem to be solved, i.e. len(types) == number of sites in system
- name (string) – The name of the PairTable. This is simply used as a convencience for identifying the table internally.
- symmetric (bool) – If True, the table will automatically set both off-diagonal values during assignment e.g. PT[‘A’,’B’] = 5 will set ‘A-B’ and ‘B-A’
-
apply
(func, inplace=True)[source]¶ Apply a function to all elements in the table in place
Parameters: - func (any object with __call__ method) – function to be called on all table elements
- inplace (bool) – If True, apply modifications to self. Otherwise, create a new PairTable.
-
exportToMatrixArray
(space=<Space.Real: 1>)[source]¶ Convenience function for converting a table of arrays to a MatrixArray
Warning
This only works if the PairTable contains numerical data that is all of the same shape that can be cast into a np.ndarray like object.
-