コード例 #1
0
def xyz2AC_huckel(atomicNumList, xyz, charge):
    import numpy as np
    mol = get_proto_mol(atomicNumList)

    conf = Chem.Conformer(mol.GetNumAtoms())
    for i in range(mol.GetNumAtoms()):
        conf.SetAtomPosition(i, (xyz[i][0], xyz[i][1], xyz[i][2]))
    mol.AddConformer(conf)

    num_atoms = len(atomicNumList)
    AC = np.zeros((num_atoms, num_atoms)).astype(int)

    mol_huckel = Chem.Mol(mol)
    mol_huckel.GetAtomWithIdx(0).SetFormalCharge(
        charge)  #mol charge arbitrarily added to 1st atom

    passed, result = rdEHTTools.RunMol(mol_huckel)
    opop = result.GetReducedOverlapPopulationMatrix()
    tri = np.zeros((num_atoms, num_atoms))
    tri[np.tril(np.ones(
        (num_atoms, num_atoms),
        dtype=bool))] = opop  #lower triangular to square matrix
    for i in range(num_atoms):
        for j in range(i + 1, num_atoms):
            pair_pop = abs(tri[j, i])
            if pair_pop >= 0.15:  #arbitry cutoff for bond. May need adjustment
                AC[i, j] = 1
                AC[j, i] = 1

    return AC, mol
コード例 #2
0
ファイル: picture.py プロジェクト: ap7422/FlavorTool
def saveimg(smile, pltnm):
    atorvastatin = Chem.MolFromSmiles(smile)
    mh = Chem.AddHs(atorvastatin)
    rdDistGeom.EmbedMolecule(mh)
    _, res = rdEHTTools.RunMol(mh)
    static_chgs = res.GetAtomicCharges()[:atorvastatin.GetNumAtoms()]
    d = Draw.MolDraw2DCairo(400, 400)
    SimilarityMaps.GetSimilarityMapFromWeights(atorvastatin,
                                               list(static_chgs),
                                               draw2d=d)
    d.FinishDrawing()
    thing = show_png(d.GetDrawingText())
    name = "http://localhost:5006/fol/static/" + pltnm + ".png"
    thing.save(
        "C:\\Users\\patil.py\\Documents\\11F-Drive\\PFastWebLocalApp\\FlavorTool\\fol\\static\\"
        + pltnm + ".png")

    p = figure(x_range=(0, 1),
               y_range=(0, 1),
               toolbar_location=None,
               plot_width=200,
               plot_height=200)
    p.xgrid.grid_line_color = None
    p.ygrid.grid_line_color = None
    p.axis.visible = False
    thing = WheelZoomTool()
    p.add_tools(thing)
    p.toolbar.active_scroll = thing

    p.image_url(url=[name], x=0, y=1, w=1, h=1)
    return p
コード例 #3
0
    def _getMolWithEHTcharges(self, mol : Chem.Mol):
        """
        Prepare the molecule and calculate the charges.

        TODO: perhaps this should be divided into more methods for more flexibility...

        :param mol:
        :return:
        """

        mol_ = Chem.RemoveHs(mol)
        mol_ = Chem.AddHs(mol_)
        Chem.EmbedMolecule(mol_)
        # should create two output files ('run.out' and 'nul') TODO: maybe this is not really needed or even desirable in the final version?
        passed, res = rdEHTTools.RunMol(mol_)
        nat = len(mol_.GetAtoms())
        charges = res.GetAtomicCharges()
        if not self.includeHs:
            mol_ = Chem.RemoveHs(mol)
        # creates a mol object with charges set as double properties on atoms of that mol object
        for i in range(nat):
            if i < len(mol_.GetAtoms()):
                mol_.GetAtomWithIdx(i).SetDoubleProp('EHTcharge', charges[i])
            else:
                break
        return mol_
コード例 #4
0
 def test4(self):
   mol = Chem.MolFromMolFile(
     os.path.join(RDConfig.RDBaseDir, "External", "YAeHMOP", "test_data", "benzene.mol"),
     removeHs=False)
   self.assertEqual(mol.GetNumAtoms(), 12)
   ok, res = rdEHTTools.RunMol(mol)
   self.assertTrue(ok)
   self.assertAlmostEqual(res.fermiEnergy, -12.804, places=3)
   self.assertAlmostEqual(res.totalEnergy, -535.026, places=3)
コード例 #5
0
 def test1(self):
   mol = Chem.MolFromMolFile(
     os.path.join(RDConfig.RDBaseDir, "External", "YAeHMOP", "test_data", "benzene.mol"),
     removeHs=False)
   self.assertEqual(mol.GetNumAtoms(), 12)
   ok, res = rdEHTTools.RunMol(mol)
   self.assertTrue(ok)
   chgs = res.GetAtomicCharges()
   self.assertAlmostEqual(chgs[1], -0.026, places=3)
   self.assertAlmostEqual(chgs[7], 0.026, places=3)
コード例 #6
0
 def test3(self):
   mol = Chem.MolFromMolFile(
     os.path.join(RDConfig.RDBaseDir, "External", "YAeHMOP", "test_data", "benzene.mol"),
     removeHs=False)
   self.assertEqual(mol.GetNumAtoms(), 12)
   ok, res = rdEHTTools.RunMol(mol)
   self.assertTrue(ok)
   opm = res.GetReducedOverlapPopulationMatrix()
   self.assertEqual(opm.shape, (int(12 * 13 / 2), ))
   self.assertAlmostEqual(opm[0], 2.7035, 3)
   self.assertAlmostEqual(opm[2], 2.7035, 3)
   self.assertAlmostEqual(opm[3], -0.0785, 3)
コード例 #7
0
 def test2(self):
     mol = Chem.MolFromMolFile(os.path.join(RDConfig.RDBaseDir, "External",
                                            "YAeHMOP", "test_data",
                                            "benzene.mol"),
                               removeHs=False)
     self.assertEqual(mol.GetNumAtoms(), 12)
     ok, res = rdEHTTools.RunMol(mol)
     self.assertTrue(ok)
     cm = res.GetReducedChargeMatrix()
     self.assertEqual(cm.shape, (12, 12))
     self.assertAlmostEqual(cm[0][0], 0.161, places=3)
     self.assertAlmostEqual(cm[1][0], 0.118, places=3)
     self.assertAlmostEqual(cm[11][10], 0.004, places=3)
コード例 #8
0
 def test2(self):
   mol = Chem.MolFromMolFile(
     os.path.join(RDConfig.RDBaseDir, "External", "YAeHMOP", "test_data", "benzene.mol"),
     removeHs=False)
   self.assertEqual(mol.GetNumAtoms(), 12)
   ok, res = rdEHTTools.RunMol(mol)
   self.assertTrue(ok)
   self.assertEqual(res.numOrbitals, 30)
   self.assertEqual(res.numElectrons, 30)
   cm = res.GetReducedChargeMatrix()
   self.assertEqual(cm.shape, (12, res.numOrbitals))
   for i in range(6):
     self.assertAlmostEqual(cm[i][0], 0.161, places=3)
     self.assertAlmostEqual(cm[i + 6][0], 0.005, places=3)
     self.assertAlmostEqual(cm[i][6], 0.1066, places=3)
     self.assertAlmostEqual(cm[i + 6][6], 0.060, places=3)
     self.assertAlmostEqual(cm[i][9], 0.167, places=3)
     self.assertAlmostEqual(cm[i + 6][9], 0.000, places=3)
コード例 #9
0
  def test5(self):
    mol = Chem.MolFromMolFile(
      os.path.join(RDConfig.RDBaseDir, "External", "YAeHMOP", "test_data", "benzene.mol"),
      removeHs=False)
    self.assertEqual(mol.GetNumAtoms(), 12)
    ok, res = rdEHTTools.RunMol(mol, keepOverlapAndHamiltonianMatrices=True)
    self.assertTrue(ok)
    orbEs = res.GetOrbitalEnergies()
    self.assertAlmostEqual(orbEs[0], -29.6302, places=3)
    self.assertAlmostEqual(orbEs[14], -12.804, places=3)
    self.assertAlmostEqual(orbEs[29], 67.0404, places=3)

    hamil = res.GetHamiltonian()
    self.assertAlmostEqual(hamil[0, 0], -21.4000, places=3)
    self.assertAlmostEqual(hamil[0, 4], -15.3224, places=3)
    self.assertAlmostEqual(hamil[4, 0], 0.0000, places=3)
    overlap = res.GetOverlapMatrix()
    self.assertAlmostEqual(overlap[0, 0], 1.0000, places=3)
    self.assertAlmostEqual(overlap[0, 4], 0.4091, places=3)
    self.assertAlmostEqual(overlap[4, 0], 0.0000, places=3)
コード例 #10
0
def xyz2AC_huckel(atomicNumList, xyz, charge):
    """
    args
        atomicNumList - atom type list
        xyz - coordinates
        charge - molecule charge
    returns
        ac - atom connectivity
        mol - rdkit molecule
    """
    mol = get_proto_mol(atomicNumList)

    conf = Chem.Conformer(mol.GetNumAtoms())
    for i in range(mol.GetNumAtoms()):
        conf.SetAtomPosition(i, (xyz[i][0], xyz[i][1], xyz[i][2]))
    mol.AddConformer(conf)

    num_atoms = len(atomicNumList)
    AC = np.zeros((num_atoms, num_atoms)).astype(int)

    mol_huckel = Chem.Mol(mol)
    mol_huckel.GetAtomWithIdx(0).SetFormalCharge(
        charge)  #mol charge arbitrarily added to 1st atom

    # Run in temporary path because rdkit generates empty "nul" and "run.out" output files
    with in_temp_path(cleanup=True) as path:
        passed, result = rdEHTTools.RunMol(mol_huckel)

    opop = result.GetReducedOverlapPopulationMatrix()
    tri = np.zeros((num_atoms, num_atoms))
    tri[np.tril(np.ones(
        (num_atoms, num_atoms),
        dtype=bool))] = opop  #lower triangular to square matrix
    for i in range(num_atoms):
        for j in range(i + 1, num_atoms):
            pair_pop = abs(tri[j, i])
            if pair_pop >= 0.15:  #arbitry cutoff for bond. May need adjustment
                AC[i, j] = 1
                AC[j, i] = 1

    return AC, mol