Ejemplo n.º 1
0
    def setUp(self):
        self.compound1 = compounds.Compound({
            "a1": "H",
            "a2": "O"
        }, {"b1": ("a1", "a2", {
            'order': 1,
            'chirality': None
        })}, {"id": "Hydroxide"})
        self.compound2 = compounds.Compound(
            {
                "a1": "H",
                "a2": "H",
                "a3": "O",
                "a4": "H"
            }, {
                "b1": ("a1", "a3", {
                    'order': 1,
                    'chirality': None
                }),
                "b2": ("a2", "a3", {
                    'order': 1,
                    'chirality': None
                }),
                "b3": ("a3", "a4", {
                    'order': 1,
                    'chirality': None
                })
            }, {"id": "Hydronium"})

        self.acid1 = Acid(self.compound2, 'a1', -1.74)
        self.base1 = Base(self.compound1, 'a2', 15.7)
        self.conditions1 = Conditions({})
        self.acidbase1 = AcidBase(self.acid1, self.base1, self.conditions1)
Ejemplo n.º 2
0
 def test_negative_charge(self):
     compound = compounds.Compound({
         "a1": "H",
         "a2": "O"
     }, {"b1": ("a1", "a2", {
         "order": 1
     })}, {})
     self.assertEqual(compound.charge, -1)
Ejemplo n.º 3
0
 def setUp(self):
     self.compound1 = compounds.Compound({
         "a1": "H",
         "a2": "O"
     }, {"b1": ("a1", "a2", {
         'order': 1,
         'chirality': None
     })}, {"id": "Hydroxide"})
     self.compound2 = compounds.Compound(
         {
             "a1": "H",
             "a2": "H",
             "a3": "O",
             "a4": "H"
         }, {
             "b1": ("a1", "a3", {
                 'order': 1,
                 'chirality': None
             }),
             "b2": ("a2", "a3", {
                 'order': 1,
                 'chirality': None
             }),
             "b3": ("a3", "a4", {
                 'order': 1,
                 'chirality': None
             })
         }, {"id": "Hydronium"})
     self.compound3 = compounds.Compound({
         'a1': 'H',
         'a2': 'O',
         'a3': 'H'
     }, {
         'b1': ('a1', 'a2', {
             'order': 1,
             'chirality': None
         }),
         'b2': ('a2', 'a3', {
             'order': 1,
             'chirality': None
         })
     }, {'id': "Water"})
     self.acid = Acid(self.compound2, 'a1', -1.74)
     self.base = Base(self.compound1, 'a2', 16)
     self.conj_acid = Acid(self.compound3, 'a3', 16)
     self.conditions = Conditions({})
Ejemplo n.º 4
0
    def test_hydroxide_hydronium(self):
        self.maxDiff = None
        parts = self.acidbase1.react()
        majors, minors = parts.major, parts.minor
        major = (Product(
            compounds.Compound({
                "a1": "H",
                "a2": "O",
                "a3": "H"
            }, {
                "b1": ("a1", "a2", {
                    'order': 1,
                    'chirality': None
                }),
                "b2": ("a2", "a3", {
                    'order': 1,
                    'chirality': None
                })
            }, {"id": "Conjugate acid of Hydroxide"}), 50),
                 Product(
                     compounds.Compound({
                         "a1": "H",
                         "a2": "O",
                         "a3": "H"
                     }, {
                         "b1": ("a1", "a2", {
                             'order': 1,
                             'chirality': None
                         }),
                         "b2": ("a2", "a3", {
                             'order': 1,
                             'chirality': None
                         })
                     }, {"id": "Conjugate base of Hydronium"}), 50))
        minor = ()
        expected = Products(major, minor)
        exp_majors, exp_minors = expected.major, expected.minor

        self.assertEqual(exp_minors, minors)
        self.assertEqual(exp_majors, majors)
Ejemplo n.º 5
0
 def setUp(self):
     self.compound1 = compounds.Compound({
         "a1": "H",
         "a2": "H",
         "a3": "O"
     }, {
         "b1": ("a1", "a3", {
             'order': 1,
             'chirality': None
         }),
         "b2": ("a2", "a3", {
             'order': 1,
             'chirality': None
         })
     }, {"id": "Water"})
Ejemplo n.º 6
0
 def test_isomorphism2(self):
     self.compound4 = compounds.Compound({
         'a1': 'H',
         'a3': 'O',
         'a2': 'H'
     }, {
         'b1': ('a1', 'a3', {
             'order': 1,
             'chirality': None
         }),
         'b2': ('a2', 'a3', {
             'order': 1,
             'chirality': None
         })
     })
     self.assertEquals(self.compound3, self.compound4)
Ejemplo n.º 7
0
 def test_positive_charge(self):
     compound = compounds.Compound(
         {
             "a1": "H",
             "a2": "H",
             "a3": "H",
             "a4": "O"
         }, {
             "b1": ("a1", "a4", {
                 "order": 1
             }),
             "b2": ("a2", "a4", {
                 "order": 1
             }),
             "b3": ("a3", "a4", {
                 "order": 1
             })
         }, {})
     self.assertEqual(compound.charge, 1)
Ejemplo n.º 8
0
    def _calculate_products(self):
        """Determines the expected products of the reaction.

        Returns
        -------
        tuple
            A tuple of tuples.  The form is something like

                (Major Product, Minor Product)

            which can be further broken down into

                ((Conj. Acid, Conj. Base, Salt), (Empty Product))


        Notes
        -----
        This will generally be the conjugate acid and base, as well as some salt
        (or other byproduct).  This method is still incomplete - it lacks
        support for generating the salt from ionic compounds.
        """

        conjugate_acid = None
        conjugate_base = None
        salt = None   # NYI

        acid, base = deepcopy(self.acid[0]), deepcopy(self.base[0])
        conjugate_acid = base.to_conjugate_acid()
        other = acid.other_info

        try:
            other['id'] = "Conjugate base of {}".format(acid.other_info['id'])
        except KeyError:
            other['id'] = "Unknown Base"
        conjugate_base = compounds.Compound(
            *self._remove_node(acid, self.acid[1]), other_info=other)
        return ((Product(conjugate_acid, 50),
                 Product(conjugate_base, 50),
                 Product(salt, 0)),
                (Product(None, 0),))
Ejemplo n.º 9
0
    def setUp(self):
        self.compound1 = compounds.Compound({
            "a1": "H",
            "a2": "H",
            "a3": "O"
        }, {
            "b1": ("a1", "a3", {
                'order': 1,
                'chirality': None
            }),
            "b2": ("a2", "a3", {
                'order': 1,
                'chirality': None
            })
        }, {"id": "Water"})
        self.compound2 = compounds.Compound(
            {
                "a1": "H",
                "a2": "H",
                "a3": "O",
                "a4": "H"
            }, {
                "b1": ("a1", "a3", {
                    'order': 1,
                    'chirality': None
                }),
                "b2": ("a2", "a3", {
                    'order': 1,
                    'chirality': None
                }),
                "b3": ("a3", "a4", {
                    'order': 1,
                    'chirality': None
                })
            }, {"id": "Hydronium"})
        self.acid1 = Acid(self.compound2, 'a1', -1.74)
        self.base1 = Base(self.compound1, 'a2', -1.74)
        self.conditions1 = Conditions({})
        self.acidbase1 = AcidBase(self.acid1, self.base1, self.conditions1)

        self.hydroiodic = Acid(
            compounds.Compound({
                "a1": "H",
                "a2": "I"
            }, {"b1": ("a1", "a2", {
                'order': 1,
                'chirality': None
            })}, {"id": "Hydroiodic acid"}), 'a1', -10)
        self.conditions2 = Conditions({
            'pka': -10,
            'acidic': True,
            'pka_molecule': self.hydroiodic,
            'pka_location': 'a1'
        })
        self.acidbase2 = AcidBase(self.acid1, self.base1, self.conditions2)

        self.hydroxide = Base(
            compounds.Compound({
                "a1": "H",
                "a2": "O",
                "a3": "Na"
            }, {
                "b1": ("a1", "a2", {
                    'order': 1,
                    'chirality': None
                }),
                "b2": ("a2", "a3", {
                    'order': 1,
                    'chirality': None
                })
            }, {"id": "Sodium Hydroxide"}), 'a2', 15.7)
        self.conditions3 = Conditions({
            'pka': 15.7,
            'basic': True,
            'pka_molecule': self.hydroxide,
            'pka_location': 'a2'
        })
        self.acidbase3 = AcidBase(self.acid1, self.base1, self.conditions3)
Ejemplo n.º 10
0
 def test_repr(self):
     assert repr(compounds._CompoundWrapper(compounds.Compound({}, {}, {})))
Ejemplo n.º 11
0
 def test_string(self):
     assert str(compounds._CompoundWrapper(compounds.Compound({}, {}, {})))
Ejemplo n.º 12
0
 def setUp(self):
     # Water
     self.compound1 = compounds.Compound({
         "a1": "H",
         "a2": "H",
         "a3": "O"
     }, {
         "b1": ("a1", "a3", {
             'order': 1,
             'chirality': None
         }),
         "b2": ("a2", "a3", {
             'order': 1,
             'chirality': None
         })
     }, {"id": "Water"})
     # Ketone
     self.compound2 = compounds.Compound(
         {
             "a1": "H",
             "a2": "H",
             "a3": "H",
             "a4": "H",
             "a5": "H",
             "a6": "H",
             "a7": "C",
             "a8": "C",
             "a9": "C",
             "a10": "O"
         }, {
             "b0": ("a1", "a7", {
                 'order': 1,
                 'chirality': None
             }),
             "b1": ("a2", "a7", {
                 'order': 1,
                 'chirality': None
             }),
             "b2": ("a3", "a7", {
                 'order': 1,
                 'chirality': None
             }),
             "b3": ("a4", "a9", {
                 'order': 1,
                 'chirality': None
             }),
             "b4": ("a5", "a9", {
                 'order': 1,
                 'chirality': None
             }),
             "b5": ("a6", "a9", {
                 'order': 1,
                 'chirality': None
             }),
             "b6": ("a7", "a8", {
                 'order': 1,
                 'chirality': None
             }),
             "b7": ("a9", "a8", {
                 'order': 1,
                 'chirality': None
             }),
             "b8": ("a8", "a10", {
                 'order': 2,
                 'chirality': None
             })
         }, {})