Skip to content

charges

EEM

Class to handle calculation of electronegativity equilibration method charges

Source code in chmpy/ext/charges.py
class EEM:
    "Class to handle calculation of electronegativity equilibration method charges"

    @staticmethod
    def calculate_charges(mol):
        """
        Calculate the partial atomic charges based on the EEM method.

        Args:
            mol (Molecule): The molecule with atoms where partial charges are desired

        Returns:
            np.ndarray: the partial charges associated the atoms in `mol`
        """
        A = []
        B = []
        for el in mol.elements:
            a, b = EEM_PARAMETERS.get(el.symbol, EEM_PARAMETERS["*"])
            A.append(a)
            B.append(b)
        N = len(mol)
        M = np.zeros((N + 1, N + 1))
        M[-1, :-1] = 1
        M[:-1, -1] = -1
        dists = mol.distance_matrix
        idx = np.triu_indices(N, k=1)
        M[idx] = EEM_KAPPA / dists[idx]
        idx = np.tril_indices(N, k=-1)
        M[idx] = EEM_KAPPA / dists[idx]
        np.fill_diagonal(M, B)
        M[N, N] = 0.0
        y = np.zeros(N + 1)
        y[:N] -= A
        y[N] = mol.charge
        return np.linalg.solve(M, y)[:N]

calculate_charges(mol) staticmethod

Calculate the partial atomic charges based on the EEM method.

Parameters:

Name Type Description Default
mol Molecule

The molecule with atoms where partial charges are desired

required

Returns:

Type Description

np.ndarray: the partial charges associated the atoms in mol

Source code in chmpy/ext/charges.py
@staticmethod
def calculate_charges(mol):
    """
    Calculate the partial atomic charges based on the EEM method.

    Args:
        mol (Molecule): The molecule with atoms where partial charges are desired

    Returns:
        np.ndarray: the partial charges associated the atoms in `mol`
    """
    A = []
    B = []
    for el in mol.elements:
        a, b = EEM_PARAMETERS.get(el.symbol, EEM_PARAMETERS["*"])
        A.append(a)
        B.append(b)
    N = len(mol)
    M = np.zeros((N + 1, N + 1))
    M[-1, :-1] = 1
    M[:-1, -1] = -1
    dists = mol.distance_matrix
    idx = np.triu_indices(N, k=1)
    M[idx] = EEM_KAPPA / dists[idx]
    idx = np.tril_indices(N, k=-1)
    M[idx] = EEM_KAPPA / dists[idx]
    np.fill_diagonal(M, B)
    M[N, N] = 0.0
    y = np.zeros(N + 1)
    y[:N] -= A
    y[N] = mol.charge
    return np.linalg.solve(M, y)[:N]