Exemplo n.º 1
0
 def __init__(self, seq=None):
     super(TestDnaForm, self).__init__(
         seq=seq,
         alphabet=alphabet,
         backbone=core.Backbone(
             structure='OC1CCOC1COP([O-])([O-])=O',
             monomer_bond_atoms=[
                 core.Atom(core.Backbone, element='C', position=4)
             ],
             monomer_displaced_atoms=[
                 core.Atom(core.Backbone, element='H', position=4)
             ]),
         bond=core.Bond(l_bond_atoms=[
             core.Atom(core.Backbone, element='O', position=1)
         ],
                        r_bond_atoms=[
                            core.Atom(core.Backbone,
                                      element='P',
                                      position=9)
                        ],
                        l_displaced_atoms=[
                            core.Atom(core.Backbone,
                                      element='H',
                                      position=1)
                        ],
                        r_displaced_atoms=[
                            core.Atom(core.Backbone,
                                      element='O',
                                      position=11,
                                      charge=-1)
                        ]))
Exemplo n.º 2
0
 def __init__(self, seq=None):
     super(TestDnaForm, self).__init__(
         seq=seq,
         alphabet=dna.canonical_dna_alphabet,
         backbone=None,
         bond=core.Bond(r_bond_atoms=[
             core.Atom(core.Monomer, element='O', position=None)
         ],
                        l_bond_atoms=[
                            core.Atom(core.Monomer,
                                      element='P',
                                      position=None)
                        ],
                        r_displaced_atoms=[
                            core.Atom(core.Monomer,
                                      element='H',
                                      position=None)
                        ],
                        l_displaced_atoms=[
                            core.Atom(core.Monomer,
                                      element='O',
                                      position=None,
                                      charge=-1)
                        ]))
Exemplo n.º 3
0
    def test_validate_bpform_bonds(self):
        class TestDnaForm(core.BpForm):
            def __init__(self, seq=None):
                super(TestDnaForm, self).__init__(
                    seq=seq,
                    alphabet=dna.canonical_dna_alphabet,
                    backbone=None,
                    bond=core.Bond(r_bond_atoms=[
                        core.Atom(core.Monomer, element='O', position=None)
                    ],
                                   l_bond_atoms=[
                                       core.Atom(core.Monomer,
                                                 element='P',
                                                 position=None)
                                   ],
                                   r_displaced_atoms=[
                                       core.Atom(core.Monomer,
                                                 element='H',
                                                 position=None)
                                   ],
                                   l_displaced_atoms=[
                                       core.Atom(core.Monomer,
                                                 element='O',
                                                 position=None,
                                                 charge=-1)
                                   ]))

        util.validate_bpform_bonds(TestDnaForm)

        alphabet = core.Alphabet()
        alphabet.monomers.A = core.Monomer(
            id='adenine',
            structure='NC1=C2N=CNC2=NC=N1',
            backbone_bond_atoms=[
                core.Atom(molecule=core.Monomer, element='N', position=6)
            ],
            backbone_displaced_atoms=[
                core.Atom(molecule=core.Monomer, element='H', position=6)
            ],
        )

        class TestDnaForm(core.BpForm):
            def __init__(self, seq=None):
                super(TestDnaForm, self).__init__(
                    seq=seq,
                    alphabet=alphabet,
                    backbone=core.Backbone(
                        structure='OC1CCOC1COP([O-])([O-])=O',
                        monomer_bond_atoms=[
                            core.Atom(core.Backbone,
                                      element='C',
                                      position=1000)
                        ],
                        monomer_displaced_atoms=[
                            core.Atom(core.Backbone, element='H', position=4)
                        ]),
                    bond=core.Bond(l_bond_atoms=[
                        core.Atom(core.Backbone, element='O', position=1)
                    ],
                                   r_bond_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='P',
                                                 position=9)
                                   ],
                                   l_displaced_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='H',
                                                 position=1)
                                   ],
                                   r_displaced_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='O',
                                                 position=11,
                                                 charge=-1)
                                   ]))

        with self.assertRaises(ValueError):
            util.validate_bpform_bonds(TestDnaForm)

        alphabet = core.Alphabet()
        alphabet.monomers.A = core.Monomer(
            id='adenine',
            structure='NC1=C2N=CNC2=NC=N1',
            backbone_bond_atoms=[
                core.Atom(molecule=core.Monomer, element='N', position=6)
            ],
            backbone_displaced_atoms=[
                core.Atom(molecule=core.Monomer, element='H', position=6)
            ],
        )

        class TestDnaForm(core.BpForm):
            def __init__(self, seq=None):
                super(TestDnaForm, self).__init__(
                    seq=seq,
                    alphabet=alphabet,
                    backbone=core.Backbone(
                        structure='OC1CCOC1COP([O-])([O-])=O',
                        monomer_bond_atoms=[
                            core.Atom(core.Backbone, element='E', position=4)
                        ],
                        monomer_displaced_atoms=[
                            core.Atom(core.Backbone, element='H', position=4)
                        ]),
                    bond=core.Bond(l_bond_atoms=[
                        core.Atom(core.Backbone, element='O', position=1)
                    ],
                                   r_bond_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='P',
                                                 position=9)
                                   ],
                                   l_displaced_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='H',
                                                 position=1)
                                   ],
                                   r_displaced_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='O',
                                                 position=11,
                                                 charge=-1)
                                   ]))

        with self.assertRaises(ValueError):
            util.validate_bpform_bonds(TestDnaForm)

        alphabet = core.Alphabet()
        alphabet.monomers.A = core.Monomer(
            id='adenine',
            structure='NC1=C2N=CNC2=NC=N1',
            backbone_bond_atoms=[
                core.Atom(molecule=core.Monomer, element='N', position=6)
            ],
            backbone_displaced_atoms=[
                core.Atom(molecule=core.Monomer, element='H', position=6)
            ],
        )

        class TestDnaForm(core.BpForm):
            def __init__(self, seq=None):
                super(TestDnaForm, self).__init__(
                    seq=seq,
                    alphabet=alphabet,
                    backbone=core.Backbone(
                        structure='OC1CCOC1COP([O-])([O-])=O',
                        monomer_bond_atoms=[
                            core.Atom(core.Backbone, element='C', position=4)
                        ],
                        monomer_displaced_atoms=[
                            core.Atom(core.Backbone, element='H', position=4)
                        ]),
                    bond=core.Bond(l_bond_atoms=[
                        core.Atom(core.Backbone, element='O', position=1)
                    ],
                                   r_bond_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='P',
                                                 position=9)
                                   ],
                                   l_displaced_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='H',
                                                 position=1)
                                   ],
                                   r_displaced_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='O',
                                                 position=11,
                                                 charge=-1)
                                   ]))

        util.validate_bpform_bonds(TestDnaForm)

        alphabet = core.Alphabet()
        alphabet.monomers.A = core.Monomer(
            id='adenine',
            structure='NC1=C2N=CNC2=NC=N1',
            backbone_bond_atoms=[
                core.Atom(molecule=core.Monomer, element='N', position=1000)
            ],
            backbone_displaced_atoms=[
                core.Atom(molecule=core.Monomer, element='H', position=6)
            ],
        )

        class TestDnaForm(core.BpForm):
            def __init__(self, seq=None):
                super(TestDnaForm, self).__init__(
                    seq=seq,
                    alphabet=alphabet,
                    backbone=core.Backbone(
                        structure='OC1CCOC1COP([O-])([O-])=O',
                        monomer_bond_atoms=[
                            core.Atom(core.Backbone, element='C', position=4)
                        ],
                        monomer_displaced_atoms=[
                            core.Atom(core.Backbone, element='H', position=4)
                        ]),
                    bond=core.Bond(l_bond_atoms=[
                        core.Atom(core.Backbone, element='O', position=1)
                    ],
                                   r_bond_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='P',
                                                 position=9)
                                   ],
                                   l_displaced_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='H',
                                                 position=1)
                                   ],
                                   r_displaced_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='O',
                                                 position=11,
                                                 charge=-1)
                                   ]))

        with self.assertRaises(ValueError):
            util.validate_bpform_bonds(TestDnaForm)

        alphabet = core.Alphabet()
        alphabet.monomers.A = core.Monomer(
            id='adenine',
            structure='NC1=C2N=CNC2=NC=N1',
            backbone_bond_atoms=[
                core.Atom(molecule=core.Monomer, element='E', position=6)
            ],
            backbone_displaced_atoms=[
                core.Atom(molecule=core.Monomer, element='H', position=6)
            ],
        )

        class TestDnaForm(core.BpForm):
            def __init__(self, seq=None):
                super(TestDnaForm, self).__init__(
                    seq=seq,
                    alphabet=alphabet,
                    backbone=core.Backbone(
                        structure='OC1CCOC1COP([O-])([O-])=O',
                        monomer_bond_atoms=[
                            core.Atom(core.Backbone, element='C', position=4)
                        ],
                        monomer_displaced_atoms=[
                            core.Atom(core.Backbone, element='H', position=4)
                        ]),
                    bond=core.Bond(l_bond_atoms=[
                        core.Atom(core.Backbone, element='O', position=1)
                    ],
                                   r_bond_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='P',
                                                 position=9)
                                   ],
                                   l_displaced_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='H',
                                                 position=1)
                                   ],
                                   r_displaced_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='O',
                                                 position=11,
                                                 charge=-1)
                                   ]))

        with self.assertRaises(ValueError):
            util.validate_bpform_bonds(TestDnaForm)

        alphabet = core.Alphabet()
        alphabet.monomers.A = core.Monomer(
            id='adenine',
            structure='NC1=C2N=CNC2=NC=N1',
            backbone_bond_atoms=[
                core.Atom(molecule=core.Monomer, element='N', position=6)
            ],
            backbone_displaced_atoms=[
                core.Atom(molecule=core.Monomer, element='H', position=6)
            ],
        )

        class TestDnaForm(core.BpForm):
            def __init__(self, seq=None):
                super(TestDnaForm, self).__init__(
                    seq=seq,
                    alphabet=alphabet,
                    backbone=core.Backbone(
                        structure='OC1CCOC1COP([O-])([O-])=O',
                        monomer_bond_atoms=[
                            core.Atom(core.Backbone, element='C', position=4)
                        ],
                        monomer_displaced_atoms=[
                            core.Atom(core.Backbone, element='H', position=4)
                        ]),
                    bond=core.Bond(l_bond_atoms=[
                        core.Atom(core.Backbone, element='O', position=1)
                    ],
                                   r_bond_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='P',
                                                 position=9)
                                   ],
                                   l_displaced_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='H',
                                                 position=1)
                                   ],
                                   r_displaced_atoms=[
                                       core.Atom(core.Backbone,
                                                 element='O',
                                                 position=11,
                                                 charge=-1)
                                   ]))

        with self.assertRaises(ValueError):
            with mock.patch('wc_utils.util.chem.OpenBabelUtils.export',
                            side_effect=['smiles1', 'inchi1', 'inchi2']):
                util.validate_bpform_bonds(TestDnaForm)

        with self.assertRaises(ValueError):
            with mock.patch.object(core.BpForm,
                                   'get_formula',
                                   return_value=EmpiricalFormula()):
                util.validate_bpform_bonds(TestDnaForm)

        with self.assertRaises(ValueError):
            with mock.patch.object(core.BpForm,
                                   'get_formula',
                                   side_effect=[
                                       EmpiricalFormula('C10H12N5O6P'),
                                       EmpiricalFormula()
                                   ]):
                util.validate_bpform_bonds(TestDnaForm)

        with self.assertRaises(ValueError):
            with mock.patch.object(core.BpForm,
                                   'get_charge',
                                   return_value=-100):
                util.validate_bpform_bonds(TestDnaForm)

        with self.assertRaises(ValueError):
            with mock.patch.object(core.BpForm,
                                   'get_charge',
                                   side_effect=[-2, -100]):
                util.validate_bpform_bonds(TestDnaForm)