Exemple #1
0
 def __get_ring_candidates(self, mol, hints):
     flags = dict([(atom, 1) for atom in mol.atoms])
     if hints:
         for atom in mol.atoms:
             rank = hints.rank(atom)
             if not rank or rank > self.max_ring_size:
                 flags[atom] = 0                    
             
     while True:
         no_change = True
         for atom in mol.atoms:
             if flags[atom]:
                 deg = mol.degree(atom)
                 if deg > 1:
                     v = 0
                     for i in xrange(deg):
                         v += flags[mol.neighbor_atom(atom, i)]
                         if v > 1:
                             break
                     if v < 2:
                         flags[atom] = 0
                         no_change = False
                 else:
                     flags[atom] = 0
                     no_change =  False
         
         if no_change:
             break
     
     atoms = [k for k, v in flags if v]
     return split(Molecule(atoms, None, mol))
Exemple #2
0
    def __make_sssr(self, part, max_ring_size):
        assert len(part.atoms) < len(part.bonds)
        rings = []

        visited_bonds = set()
        for bond in part.bonds:
            if bond not in visited_bonds: 
                ring = RingFinder.find_ring(part, bond, max_ring_size)
                if ring:
                    rings.append(ring)
                    for i in ring.bond:
                        visited_bonds.add(i)
        
        assert len(rings) == len(part.bonds) - len(part.atoms) + 1
        
        self.rings += rings
        if len(visited_bonds) == len(part.bonds):
            self.blocks[part] = rings
        else:
            self.blocks[part] = split(Molecule(None, list(visited_bonds), part))
Exemple #3
0
def save_mol_set(cursor, frame, data, vdw_radius=None, tor=0.2):
    mol = parse_mol(data, vdw_radius, tor)
    molset = split(mol)
    for molI in molset:
        f = formula(molI)
        s = format_mol(molI, 'mol')
        code, _, k = inchi(s)
        moltype = save_mol_type(cursor, len(molI.atoms), len(molI.bonds), f, k, code)
        atomid = [mol.atoms.index(i) for i in molI.atoms]

        bondid = []
        for bond in molI.bonds:
            atom1 = mol.atoms.index(bond.atom1)
            atom2 = mol.atoms.index(bond.atom2)
            if atom1 > atom2:
                atom1, atom2 = atom2, atom1
            bondid.append((atom1, atom2))
        
        molid = save_molecule(cursor, moltype, atomid, bondid)
        cursor.execute(SQL_INSERT_MOL_IN_FRAME, (frame, molid))