2017-12-04 4 views
2

Ich brauche einige Coulomb-Matrizen von Molekülen für eine maschinelle Lernaufgabe. Coulomb-Matrix? Hier ist eine paper BeschreibungWie erstellt man Coulomb Matrix mit Python?

Ich fand das Python-Paket molml, die eine Methode dafür hat. Jedoch kann ich nicht herausfinden, wie man die API nur für ein einzelnes Molekül verwendet. In allen examples stellen sie die Methode dar, die mit zwei Molekülen bezeichnet wird, warum?

Wie das Beispiel des Verfahrens sieht vor:

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]) 

Ich brauche etwas wie folgt aus:

atomnames = [list of atomsymbols] 
atomcoords = [list of [x,y,z] for the atoms] 
coulombMatrice = CoulombMatrix((atomnames,atomcoords) 

ich auch eine andere lib (QML) wich verspricht die Möglichkeit, Coulomb-Matrizen zu erzeugen, sondern, Ich bin nicht in der Lage, es unter Windows zu installieren, weil es von Linux GCC-Fortran Compilern abhängt, ich habe bereits cygwin und GCC-Fortran für diesen Zweck installiert.

Danke, Jungs

Antwort

0

ich meine eigene Lösung für das Problem implementiert haben. Es gibt viel Raum für Verbesserungen. Z.B. zufällig sortierte Coulomb-Matrix und Sack von Anleihen sind noch nicht implementiert.

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 
Verwandte Themen