def penalty_birads_replacing_lone_pairs_test(self):
     """Test that birads on `S u2 p0` are penalized"""
     adj = """
     multiplicity 3
     1 S u2 p0 c0 {2,D} {3,D}
     2 O u0 p2 c0 {1,D}
     3 O u0 p2 c0 {1,D}
     """
     mol = Molecule().fromAdjacencyList(adj)
     mol.update()
     mol_list = generate_resonance_structures(mol, keep_isomorphic=False, filter_structures=True)
     for mol in mol_list:
         if mol.reactive:
             for atom in mol.vertices:
                 if atom.isSulfur():
                     self.assertNotEquals(atom.radicalElectrons, 2)
     self.assertEqual(len(mol_list), 3)
     self.assertEqual(sum([1 for mol in mol_list if mol.reactive]), 2)
示例#2
0
 def penalty_birads_replacing_lone_pairs_test(self):
     """Test that birads on `S u2 p0` are penalized"""
     adj = """
     multiplicity 3
     1 S u2 p0 c0 {2,D} {3,D}
     2 O u0 p2 c0 {1,D}
     3 O u0 p2 c0 {1,D}
     """
     mol = Molecule().from_adjacency_list(adj)
     mol.update()
     mol_list = generate_resonance_structures(mol, keep_isomorphic=False, filter_structures=True)
     for mol in mol_list:
         if mol.reactive:
             for atom in mol.vertices:
                 if atom.is_sulfur():
                     self.assertNotEquals(atom.radical_electrons, 2)
     self.assertEqual(len(mol_list), 3)
     self.assertEqual(sum([1 for mol in mol_list if mol.reactive]), 2)
    def get_representative_molecule(self, mode='minimal', update=True):

        if mode == 'minimal':
            # create a molecule from fragment.vertices.copy
            mapping = self.copyAndMap()

            # replace CuttingLabel with H
            atoms = []
            for vertex in self.vertices:

                mapped_vertex = mapping[vertex]
                if isinstance(mapped_vertex, CuttingLabel):

                    # replace cutting label with atom H
                    atom_H = Atom(element=getElement('H'),
                                  radicalElectrons=0,
                                  charge=0,
                                  lonePairs=0)

                    for bondedAtom, bond in mapped_vertex.edges.iteritems():
                        new_bond = Bond(bondedAtom, atom_H, order=bond.order)

                        bondedAtom.edges[atom_H] = new_bond
                        del bondedAtom.edges[mapped_vertex]

                        atom_H.edges[bondedAtom] = new_bond

                    mapping[vertex] = atom_H
                    atoms.append(atom_H)

                else:
                    atoms.append(mapped_vertex)

            # Note: mapping is a dict with
            # key: self.vertex and value: mol_repr.atom
            mol_repr = Molecule()
            mol_repr.atoms = atoms
            if update:
                mol_repr.update()

            return mol_repr, mapping
    def assign_representative_molecule(self):

        # create a molecule from fragment.vertices.copy
        mapping = self.copyAndMap()

        # replace CuttingLabel with CC
        atoms = []
        additional_atoms = []
        additional_bonds = []
        for vertex in self.vertices:

            mapped_vertex = mapping[vertex]
            if isinstance(mapped_vertex, CuttingLabel):

                # replace cutting label with atom C
                atom_C1 = Atom(element=getElement('C'),
                               radicalElectrons=0,
                               charge=0,
                               lonePairs=0)

                for bondedAtom, bond in mapped_vertex.edges.iteritems():
                    new_bond = Bond(bondedAtom, atom_C1, order=bond.order)

                    bondedAtom.edges[atom_C1] = new_bond
                    del bondedAtom.edges[mapped_vertex]

                    atom_C1.edges[bondedAtom] = new_bond

                # add hydrogens and carbon to make it CC
                atom_H1 = Atom(element=getElement('H'),
                               radicalElectrons=0,
                               charge=0,
                               lonePairs=0)

                atom_H2 = Atom(element=getElement('H'),
                               radicalElectrons=0,
                               charge=0,
                               lonePairs=0)

                atom_C2 = Atom(element=getElement('C'),
                               radicalElectrons=0,
                               charge=0,
                               lonePairs=0)

                atom_H3 = Atom(element=getElement('H'),
                               radicalElectrons=0,
                               charge=0,
                               lonePairs=0)

                atom_H4 = Atom(element=getElement('H'),
                               radicalElectrons=0,
                               charge=0,
                               lonePairs=0)

                atom_H5 = Atom(element=getElement('H'),
                               radicalElectrons=0,
                               charge=0,
                               lonePairs=0)

                atoms.append(atom_C1)

                additional_atoms.extend(
                    [atom_H1, atom_H2, atom_H3, atom_H4, atom_H5, atom_C2])

                additional_bonds.extend([
                    Bond(atom_C1, atom_H1, 1),
                    Bond(atom_C1, atom_H2, 1),
                    Bond(atom_C2, atom_H3, 1),
                    Bond(atom_C2, atom_H4, 1),
                    Bond(atom_C2, atom_H5, 1),
                    Bond(atom_C1, atom_C2, 1)
                ])

            else:
                atoms.append(mapped_vertex)

        mol_repr = Molecule()
        mol_repr.atoms = atoms
        for atom in additional_atoms:
            mol_repr.addAtom(atom)
        for bond in additional_bonds:
            mol_repr.addBond(bond)
        # update connectivity
        mol_repr.update()

        # create a species object from molecule
        self.mol_repr = mol_repr

        return mapping