2017-12-04 5 views
2

기계 학습 과제를 위해 분자의 쿨롱 행렬이 필요합니다. 쿨롱 매트릭스? 여기에 paper이 있습니다.Python으로 Coulomb Matrix를 만드는 방법은 무엇입니까?

나는 방법이있는 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]) 

나는 이런 식으로 뭔가가 필요 : 예는 방법을 제공하는 방법

나는 또한 다른 lib 디렉토리를 발견
atomnames = [list of atomsymbols] 
atomcoords = [list of [x,y,z] for the atoms] 
coulombMatrice = CoulombMatrix((atomnames,atomcoords) 

(QML) 느릅 나무는 쿨롱 행렬을 생성 할 수있는 가능성이 약속을하지만,을, 나는 리눅스 gcc-fortran 컴파일러에 의존하기 때문에 윈도우에 설치할 수 없다. 이미 cygwin과 gcc-fortran을이 목적으로 설치했다.

감사합니다.

답변

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