TrustedSmiles.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 » TrustedSmiles.py
"""TrustedSmiles

exports
  molecule = trusted_smiles(molecule)
    returns a molecule that trusts the original input for the
    declaration of aromaticity.


 This is a really stupid algorithm to accept standard smiles input
 and basically trust it to be correct.

 Essentially all non specified bonds are converted to either
 aromatic or single bonds depending on two things

 An aromatic bond must:
  1 be between two aromatic atoms
  2 must be in a ring with either unspecified
    bonds or aromatic bonds.

 Otherwise it is considered a single bond.

 BUG
 There is one class of degenerate cases for this stupid
 algorithm for pre Daylight 4.71 output


     ___
    / o \       Imagine three aromatic rings surrounding
    \___/        a non aromatic ring
 ___/   \___    If the non aromatic ring doesn't have it's
/ o \___/ o \    single bonds specified, then the single bonds
\___/   \___/    and hence the inner ring will be considered aromatic.

 This algorithm really is for testing purposes, so don't get your
 knickers in a bunch :)
"""
def atoms_are_aromatic(atoms):
    for atom in atoms:
        if not atom.aromatic:
            return 0
    return 1

def bonds_are_unspecified_or_aromatic(bonds):
    for bond in bonds:
        if bond.fixed and not bond.aromatic:
            return 0
    return 1

def trusted_smiles(molecule):
    """(molecule)->molecule
    Trust the original smiles string in order to generate the proper
    aromaticity.  Will produce odd results with some smiles strings
    produced by early versions of Daylight (pre 4.71)"""



    for cycle in molecule.cycles:
        if atoms_are_aromatic(cycle.atoms) and \
           bonds_are_unspecified_or_aromatic(cycle.bonds):
            cycle.set_aromatic()

    # set the rest to single bonds
    for bond in molecule.bonds:
        if not bond.fixed:
            bond.bondtype = bond.bondorder = 1
            bond.symbol = "-"
            bond.fixed = 1
            
    # check the valences of the atoms
    # set the symmetry order to the input order
    index = 0
    for atom in molecule.atoms:
        atom.symorder = index
        if atom.valences:
            lowestValence = atom.valences[0]
            sumBondOrders = atom.sumBondOrders()
            original_hcount = atom.hcount + atom.explicit_hcount
            atom.hcount = max(original_hcount, lowestValence + atom.charge - sumBondOrders)
            atom.imp_hcount = atom.hcount - original_hcount

##            if atom.hcount + sumBondOrders > lowestValence:
##                if atom.aromatic and atom.symbol == "N" and atom.hcount == 1:
##                    # pyrole nitrogen (maybe)
##                    # skip it
##                    pass
##                #else:
##                #    print "Warning High Valence Atom", atom.index
        index += 1
    

    return molecule

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