2017-12-04 3 views
2

機械学習のためのクーロン行列の分子が必要です。 クーロン行列?ここにはpaperが記載されていますPythonでクーロン行列を作成するには?

私にはpythonパッケージmolmlがあり、それにはメソッドがあります。しかし、私はどのように単一の分子のAPIを使用するかを把握することはできません。すべてexamplesでは、それらは2つの分子で呼ばれるメソッドを提供します、なぜですか?

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(QML)はウィッヒは、クーロン行列を生成する可能性を約束したが、見つかった例は、方法を提供方法

私はそれをLinuxのgcc-fortranコンパイラに依存しているので、私はWindowsにインストールすることができません。私はすでにこの目的のために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 
関連する問題