Ejemplo n.º 1
0
def convertCycleToGroup(cycle):
    """
    This function converts a list of atoms in a cycle to a functional Group object
    """
    from rmgpy.molecule.group import GroupAtom, GroupBond, Group
    
    # Create GroupAtom object for each atom in the cycle, label the first one in the cycle with a *
    groupAtoms = {}
    bonds = []
    for atom in cycle:
        groupAtoms[atom] = GroupAtom(atomType=[atom.atomType],
                                     radicalElectrons=[0],
                                     label='*' if cycle.index(atom)==0 else '')
                
    group = Group(atoms=groupAtoms.values())            
    
    # Create GroupBond for each bond between atoms in the cycle, but not outside of the cycle
    for atom in cycle:
        for bondedAtom, bond in atom.edges.iteritems():
            if bondedAtom in cycle:
                # create a group bond with the same bond order as in the original molecule,
                # if it hasn't already been created
                if not group.hasBond(groupAtoms[atom],groupAtoms[bondedAtom]):
                    group.addBond(GroupBond(groupAtoms[atom],groupAtoms[bondedAtom],order=[bond.order]))
            else:
                pass
        
    group.update()
    
    return group
            for atom in atoms[s0:]:
                atom.props['inRing'] = True
        # Label atoms
        atoms[0].label = '*1'
        if a > 1:
            atoms[1].label = '*4'
        if a > 2:
            atoms[-1].label = '*5'
        if a > 3:
            for i, atom in enumerate(atoms[2:-1]):
                atom.label = '*{0}'.format(i + 6)
        # Add to group
        for atom in reversed(atoms):
            new_group.addAtom(atom)
        # Add bond to newly added atoms
        new_group.addBond(
            GroupBond(new_group.atoms[1], atoms[-1], order=[1, 2, 3, 1.5]))
        # Create bonds
        if a > 1:
            bonds = [
                GroupBond(atoms[i], atoms[i + 1], order=[1, 2, 3, 1.5])
                for i in range(a - 1)
            ]
            for bond in bonds:
                new_group.addBond(bond)

    # Add remaining atoms
    if b > 0:
        # Create atoms
        atoms = [
            GroupAtom(atomType=['R!H'],
                      radicalElectrons=None,