如何用Python创建库仑矩阵?

如何用Python创建库仑矩阵?,python,data-structures,molecule,Python,Data Structures,Molecule,我需要一些分子库仑矩阵来完成机器学习任务。 库仑矩阵?这里有一个描述它的例子 我找到了python包,它有一个方法。然而,我不知道如何仅对单个分子使用api。他们提供的所有方法都是用两个分子调用的,为什么 示例如何提供方法: H2 = (['H', 'H'], [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]]) HCN = (['H', 'C', 'N'], [[-1.0, 0.0, 0.0], [ 0.0, 0.0,

我需要一些分子库仑矩阵来完成机器学习任务。 库仑矩阵?这里有一个描述它的例子

我找到了python包,它有一个方法。然而,我不知道如何仅对单个分子使用api。他们提供的所有方法都是用两个分子调用的,为什么

示例如何提供方法:

H2 = (['H', 'H'],
      [[0.0, 0.0, 0.0],
      [1.0, 0.0, 0.0]])

HCN = (['H', 'C', 'N'],
       [[-1.0, 0.0, 0.0],
        [ 0.0, 0.0, 0.0],
        [ 1.0, 0.0, 0.0]])

feat.transform([H2, HCN])
我需要这样的东西:

 atomnames = [list of atomsymbols]
 atomcoords = [list of [x,y,z] for the atoms] 
 coulombMatrice = CoulombMatrix((atomnames,atomcoords)
我还发现了另一个lib(),它承诺可以生成库仑矩阵,但是,我无法在windows上安装它,因为它依赖于linux gcc fortran编译器,我已经为此安装了cygwin和gcc fortran


谢谢各位,我已经为这个问题实施了自己的解决方案。还有很大的改进空间。例如,随机排序的库仑矩阵和键袋仍未实现

    import numpy as np

def get_coulombmatrix(molecule, largest_mol_size=None):
    """
    This function generates a coulomb matrix for the given molecule
    if largest_mol size is provided matrix will have dimension lm x lm.
    Padding is provided for the bottom and right _|
    """
    numberAtoms = len(molecule.atoms)
    if largest_mol_size == None or largest_mol_size == 0: largest_mol_size = numberAtoms

    cij = np.zeros((largest_mol_size, largest_mol_size))

    xyzmatrix = [[atom.position.x, atom.position.y, atom.position.z] for atom in molecule.atoms]
    chargearray = [atom.atomic_number for atom in molecule.atoms]

    for i in range(numberAtoms):
        for j in range(numberAtoms):
            if i == j:
                cij[i][j] = 0.5 * chargearray[i] ** 2.4  # Diagonal term described by Potential energy of isolated atom
            else:
                dist = np.linalg.norm(np.array(xyzmatrix[i]) - np.array(xyzmatrix[j]))
                cij[i][j] = chargearray[i] * chargearray[j] / dist  # Pair-wise repulsion
    return cij

关于“0.5*chargearray[i]**2.4”的关系从何而来?除了“Rupp et al Phys.Rev.Lett.,108(5):05830112012”中的一行解释外,你知道在哪里可以找到关于这种关系如何推导的更详细解释吗?