def _DoubleBondCenters(molecule): """Treat the double bond centers.""" # . Find all double bonds between two sp2 carbons. dcenters = [] edcenters = [] zdcenters = [] udcenters = [] for (b, bond) in enumerate(molecule.connectivity.bonds): if bond.type is DoubleBond(): i = bond.i j = bond.j atomi = molecule.atoms[i] atomj = molecule.atoms[j] if ( atomi.atomicNumber == 6 ) and ( atomi.connections == 3 ) and \ ( atomj.atomicNumber == 6 ) and ( atomj.connections == 3 ): # . Save the bond. dcenters.append(b) # . Get the connected atoms. iatoms = molecule.connectivity.bonds.GetConnectedAtoms(i) iatoms.remove(j) jatoms = molecule.connectivity.bonds.GetConnectedAtoms(j) jatoms.remove(i) # . Assign priorities. oiatoms = _CIPPriorityOrderer(molecule, i, iatoms) ojatoms = _CIPPriorityOrderer(molecule, j, jatoms) if (oiatoms is not None) and (ojatoms is not None): label = _DoubleBondCenterLabel(molecule.coordinates3, i, oiatoms[0], j, ojatoms[0]) if label == "E": edcenters.append(b) else: zdcenters.append(b) # . Cannot assign priorities to the atoms. else: udcenters.append(b) return (dcenters, edcenters, zdcenters, udcenters)
def Finalize(self): """Create a final connectivity. To be used once all AddAtom and AddBond calls have been made. """ # . Define the rings and flag ring atoms. self.FindRings() # . Atom checks. for atom in self.atoms: atom.VerifyAromaticity() atom.SetValence() atom.AddImplicitHydrogens() atom.VerifyChirality() # . Bond checks - change non-aromatic to aromatic bonds between atoms. for bond in self.bonds: if bond.atom1.isAromatic and bond.atom2.isAromatic and ( not bond.type.isAromatic): if bond.type is SingleBond(): bond.type = AromaticSingleBond() elif bond.type is DoubleBond(): bond.type = AromaticDoubleBond() else: raise SMILESConnectivityError( "Invalid bond type between aromatic atoms.", bond=bond) # . Global checks. self.VerifyAromaticity() self.RemoveExplicitHydrogens() self.IndexAtoms()
def _MakeDefaultVariants(): """Make variants for the default distribution.""" # . Initialization. variants = [] # . CTerminal. variants.append( PDBComponentVariant(label="C Terminal", atomsToDelete=["HXT"], formalCharges={"OXT": -1})) # . NTerminal - general case and UNK. atomsToAdd = [ PDBComponentAtom(atomicNumber=1, label="H1", pdbAlign=0, toFollow="N"), PDBComponentAtom(atomicNumber=1, label="H2", pdbAlign=0, toFollow="H1"), PDBComponentAtom(atomicNumber=1, label="H3", pdbAlign=0, toFollow="H2") ] bondsToAdd = [ PDBComponentBond(atomLabel1="H1", atomLabel2="N", bondType=SingleBond()), PDBComponentBond(atomLabel1="H2", atomLabel2="N", bondType=SingleBond()), PDBComponentBond(atomLabel1="H3", atomLabel2="N", bondType=SingleBond()) ] variants.append( PDBComponentVariant(label="N Terminal", atomsToAdd=atomsToAdd, atomsToDelete=["H", "H2"], formalCharges={"N": +1}, bondsToAdd=bondsToAdd)) variants.append( PDBComponentVariant(componentLabel="UNK", label="N Terminal", atomsToAdd=atomsToAdd, atomsToDelete=["H", "H2"], formalCharges={"N": +1}, bondsToAdd=bondsToAdd)) # . NTerminal - PRO. atomsToAdd = [ PDBComponentAtom(atomicNumber=1, label="H2", pdbAlign=0, toFollow="N"), PDBComponentAtom(atomicNumber=1, label="H3", pdbAlign=0, toFollow="H2") ] bondsToAdd = [ PDBComponentBond(atomLabel1="H2", atomLabel2="N", bondType=SingleBond()), PDBComponentBond(atomLabel1="H3", atomLabel2="N", bondType=SingleBond()) ] variants.append( PDBComponentVariant(componentLabel="PRO", label="N Terminal", atomsToAdd=atomsToAdd, atomsToDelete=["H"], formalCharges={"N": +1}, bondsToAdd=bondsToAdd)) # . Deprotonated ASP and GLU. variants.append( PDBComponentVariant(componentLabel="ASP", label="Deprotonated", atomsToDelete=["HD2"], formalCharges={"OD2": -1})) variants.append( PDBComponentVariant(componentLabel="GLU", label="Deprotonated", atomsToDelete=["HE2"], formalCharges={"OE2": -1})) # . Histidine variants. # . Doubly protonated - leave as is but shift charge to Nepsilon. bondTypes = [ PDBComponentBond(atomLabel1="CE1", atomLabel2="ND1", bondType=SingleBond()), PDBComponentBond(atomLabel1="CE1", atomLabel2="NE2", bondType=DoubleBond()) ] variants.append( PDBComponentVariant(componentLabel="HIS", label="Doubly Protonated", formalCharges={ "ND1": 0, "NE2": +1 }, bondTypes=bondTypes)) # . Delta protonated. bondTypes = [ PDBComponentBond(atomLabel1="CE1", atomLabel2="ND1", bondType=SingleBond()), PDBComponentBond(atomLabel1="CE1", atomLabel2="NE2", bondType=DoubleBond()) ] variants.append( PDBComponentVariant(componentLabel="HIS", label="Delta Protonated", atomsToDelete=["HE2"], formalCharges={ "ND1": 0, "NE2": 0 }, bondTypes=bondTypes)) # . Epsilon protonated. variants.append( PDBComponentVariant(componentLabel="HIS", label="Epsilon Protonated", atomsToDelete=["HD1"], formalCharges={ "ND1": 0, "NE2": 0 })) # . Fully deprotonated. variants.append( PDBComponentVariant(componentLabel="HIS", label="Fully Deprotonated", atomsToDelete=["HD1", "HE2"], formalCharges={ "ND1": 0, "NE2": -1 })) # . Finish up. return variants
#=================================================================================================================================== # . Classes and functions to read MOL2 files. #=================================================================================================================================== from pCore import Coordinates3, logFile, LogFileActive, Real1DArray, TextFileReader from ExportImport import _Importer from pMolecule import CrystalClass_FromSpaceGroupNumber, PeriodicTable, System, SymmetryParameters, \ AromaticSingleBond, DoubleBond, SingleBond, TripleBond, UndefinedBond #=================================================================================================================================== # . Definitions. #=================================================================================================================================== # . Bond type definitions. _MOL2BONDTYPES = { "1": SingleBond(), "2": DoubleBond(), "3": TripleBond(), "am": SingleBond(), "ar": AromaticSingleBond(), "du": UndefinedBond(), "un": UndefinedBond(), "nc": None } # . Generic (non-element) atom types. _GENERICATOMTYPES = ("Any", "Du", "Hal", "Het", "Hev", "LP") # . Section header. _RTISTRING = "@<TRIPOS>"
"""PDB Components.""" import os, os.path from pCore import logFile, LogFileActive from pMolecule import AromaticSingleBond, DoubleBond, SingleBond, TripleBond, UndefinedBond, \ MMSequenceAtom, MMSequenceComponent, MMSequenceLink, MMSequenceVariant, \ Sequence, System #=================================================================================================================================== # . Parameters. #=================================================================================================================================== # . Bond label/object mappings. _BondLabelObjectMapping = { "Aromatic Single": AromaticSingleBond(), "Double": DoubleBond(), "Single": SingleBond(), "Triple": TripleBond(), "Undefined": UndefinedBond() } _BondObjectLabelMapping = { AromaticSingleBond(): "Aromatic Single", DoubleBond(): "Double", SingleBond(): "Single", TripleBond(): "Triple", UndefinedBond(): "Undefined" } # . Key separators. _KeyTokenSeparator = "_"
from pMolecule import DoubleBond, NullBond, SingleBond, TripleBond, PeriodicTable from SMILESUtilities import ELEMENTSAROMATIC, ELEMENTSORGANIC, SMILESAtom, SMILESBond, SMILESConnectivity, SMILESConnectivityError #=============================================================================== # . Parameters. #=============================================================================== # . Tokens used for parsing Smiles strings. # . Bonds - no aromaticity distinction is made here. _BONDTOKENS = { ".": NullBond(), "-": SingleBond(), "/": SingleBond(), "\\": SingleBond(), ":": SingleBond(), "=": DoubleBond(), "#": TripleBond() } # . Charge. _CHARGETOKENS = { "+": 1, "++": 2, "+++": 3, "++++": 4, "-": -1, "--": -2, "---": -3, "----": -4 }
# . License : CeCILL French Free Software License (http://www.cecill.info) #------------------------------------------------------------------------------- """Classes and functions for reading PDB chemical component files in mmCIF format.""" from pCore import logFile, LogFileActive, TextFileReader from pMolecule import AromaticSingleBond, DoubleBond, SingleBond, TripleBond, UndefinedBond, \ PeriodicTable from PDBComponent import PDBComponent, PDBComponentAtom, PDBComponentBond #=================================================================================================================================== # . Parameters. #=================================================================================================================================== # . Bond strings. _BondStrings = { "AROM": AromaticSingleBond(), "DOUB": DoubleBond(), "SING": SingleBond(), "TRIP": TripleBond() } #=================================================================================================================================== # . Class. #=================================================================================================================================== class PDBComponentCIFFileReader(TextFileReader): """PDBComponentCIFFileReader is the class for PDB chemical component files in mmCIF format that are to be read.""" # . Some simplicity is assumed in the parsing as all data entries are of the form: # . data_XXX followed by "#". # . general info. followed by "#". # . atom info. followed by "#".
#=================================================================================================================================== # . Parameters. #=================================================================================================================================== # . Atom type. _ATOMTYPE = "Any" # . The charge type. _CHARGETYPE = "NO_CHARGES" # . The maximum line length. _MAXIMUMLINELENGTH = 80 # . Bond type definitions. _MOL2BONDTYPES = { SingleBond ( ) : "1" , \ DoubleBond ( ) : "2" , \ TripleBond ( ) : "3" , \ AromaticSingleBond ( ) : "ar", \ AromaticDoubleBond ( ) : "ar", \ UndefinedBond ( ) : "un" } # . The molecule type. _MOLECULETYPE = "SMALL" # . Section header. _RTISTRING = "@<TRIPOS>" #=================================================================================================================================== # . MOL2 file writer class. #===================================================================================================================================
#------------------------------------------------------------------------------- #=================================================================================================================================== # . Classes and functions to read MOL and SDF files. #=================================================================================================================================== from pCore import Coordinates3, logFile, LogFileActive, TextFileReader from ExportImport import _Importer from pMolecule import Atom, PeriodicTable, System, \ AromaticSingleBond, DoubleBond, SingleBond, TripleBond, UndefinedBond #=================================================================================================================================== # . Definitions. #=================================================================================================================================== # . Bond type definitions. _MOLBONDTYPES = { 1 : SingleBond ( ), \ 2 : DoubleBond ( ), \ 3 : TripleBond ( ), \ 4 : AromaticSingleBond ( ) } # . Charge definitions. _CHARGECODES = {1: 3, 2: 2, 3: 1, 4: 0, 5: -1, 6: -2, 7: -3} #=================================================================================================================================== # . MOL file reader class. #=================================================================================================================================== class MOLFileReader(TextFileReader): """MOLFileReader is the class for MOL or SDF files that are to be read.""" def Parse(self, log=logFile): """Parsing.""" if not self.QPARSED:
"""Classes and functions for writing MOL files.""" from pCore import Coordinates3, TextFileWriter, TextFileWriterError from ExportImport import _Exporter from pMolecule import PeriodicTable, System, \ AromaticSingleBond, DoubleBond, SingleBond, TripleBond #=================================================================================================================================== # . Parameters. #=================================================================================================================================== # . The maximum line length. _MAXIMUMLINELENGTH = 80 # . Bond type definitions. _MOLBONDTYPES = { SingleBond ( ) : 1, \ DoubleBond ( ) : 2, \ TripleBond ( ) : 3, \ AromaticSingleBond ( ) : 4 } #=================================================================================================================================== # . MOL file writer class. #=================================================================================================================================== class MOLFileWriter(TextFileWriter): """MOLFileWriter is the class for MOL files that are to be written.""" def WriteFrame(self, system, label=None, xyz=None): """Write a single frame.""" # . Check the data. if xyz == None: xyz = system.coordinates3 if (xyz is None) or (not isinstance( xyz, Coordinates3)) or (xyz.rows != len(system.atoms)):