3

我需要一些库仑矩阵来完成机器学习任务。库仑矩阵?这是一篇描述它的论文

我找到了 python 包molml,它有一个方法。但是我不知道如何仅将 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)

我还发现了另一个库(QML),它承诺可以生成库仑矩阵,但是,我无法在 Windows 上安装它,因为它依赖于 linux gcc-fortran 编译器,我已经为此安装了 cygwin 和 gcc-fortran .

感谢你们

4

1 回答 1

0

我已经针对该问题实施了自己的解决方案。有很大的改进空间。例如,随机排序的库仑矩阵和债券袋仍然没有实现。

    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
于 2017-12-06T21:18:18.690 回答