Hybrid.py :  » Development » Frowns » frowns » perception » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » Frowns 
Frowns » frowns » perception » Hybrid.py
SP3 = "SP3"
SP2 = "SP2"
SP = "SP"
SD3 = "SD3"
DSP3 = "DSP3"
D2SP3 = "D2SP3"
ANY = None

# symbol, connected atoms, charge

_hybrid = {
    ("C", 4, 0): SP3,
    ("C", 3, -1): SP3,
    ("C", 3, 0): SP2,
    ("C", 4, +1): SP2,
    ("C", 2, ANY): SP,
    ("C", 1, 0): SP2,
    ("C", 1, -1): SP,
    
    ("N", 4, +1): SP3,
    ("N", 3, 0): SP3,
    ("N", 3, +1): SP2,
    ("N", 2, ANY): SP2,
    ("N", 1, -1): SP2,
    ("N", 1, 0): SP,

    ("O", 2, 0): SP3,
    ("O", 1, -1): SP3,
    ("O", 1, 0): SP2,
    ("O", 2, 1): SP2,

    ("P", 3, 0): SP3,
    ("P", 4, 1): SP3,
    ("P", 4, 0): SD3,
    ("P", 5, 0): DSP3,
    ("P", 6, 0): D2SP3,

    ("S", 2, 0): SP3,
    ("S", 1, -1): SP3,
    ("S", 1, 0): SP2,
    ("S", 3, 1): SP3,
    ("S", 3, 0): SD3,
    ("S", 4, 0): SD3,
}


def getHybridAtoms(molecule):
    """(molecule) -> mark all hybridiced atoms in a molecule
    that is set the atom.hybrid property to the correct value"""
    for atom in molecule.atoms:
        
        if atom.aromatic:
            # assume the combined bondorder is 3
            atom.hybrid = SP2
            continue
        symbol = atom.symbol
        hcount = atom.valences[0] - atom.sumBondOrders()
        connections = len(atom.bonds) + hcount
        charge = atom.charge
        if atom.symbol in ["C", "N"] and connections == 2:
            charge = ANY

        atom.hybrid =  _hybrid.get((symbol, connections, charge), "")
        #print atom, `atom`, hcount, atom.hybrid

        
        
            
if __name__ == "__main__":
    from frowns import Smiles
    from frowns.perception import TrustedSmiles,sssr
    
    smiles = "CC(=O)OC1C(N(c2c(CC1c1ccc(OC)cc1)cc(cc2)Oc1ccccc1)CCN(C)C)=O"
    smiles = "O=C1NC(N)=NC2=C1N=CNC2"
    #smiles = "O=C1C=CC(=O)C=C1"

    print smiles
    mol = Smiles.smilin(smiles, [sssr.sssr])
            
    getHybridAtoms(mol)
    for cycle in mol.cycles:
        print [(atom, atom.symbol, atom.hybrid) for atom in cycle.atoms]

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.