【问题标题】:How to create Coulomb Matrix with Python?如何用 Python 创建库仑矩阵?
【发布时间】:2017-12-04 16:17:27
【问题描述】:

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

我找到了python包molml,它有一个方法。但是我不知道如何仅将 api 用于单个分子。在所有examples 中,他们提供的方法是用两个分子调用的,为什么?

示例如何提供方法:

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 用于此目的。

谢谢大家

【问题讨论】:

    标签: python data-structures molecule


    【解决方案1】:

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

        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):058301, 2012”中的单行解释之外,您知道在哪里可以找到关于如何得出这种关系的更详细的解释吗?
    猜你喜欢
    • 2014-05-17
    • 2022-12-04
    • 2012-11-01
    • 1970-01-01
    • 2014-06-20
    • 2019-03-23
    • 1970-01-01
    • 2015-11-22
    • 2018-04-24
    相关资源
    最近更新 更多