man*_*iac 5 python data-structures molecule
我需要一些分子库仑矩阵来完成机器学习任务。库仑矩阵?这是一篇描述它的论文
我找到了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])
Run Code Online (Sandbox Code Playgroud)
我需要这样的东西:
atomnames = [list of atomsymbols]
atomcoords = [list of [x,y,z] for the atoms]
coulombMatrice = CoulombMatrix((atomnames,atomcoords)
Run Code Online (Sandbox Code Playgroud)
我还找到了另一个库(QML),它承诺生成库仑矩阵的可能性,但是,我无法在 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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2029 次 |
最近记录: |