Beispiel #1
0
def test_add_node():
    a = Molecule(
        {'a1': 'H', 'a2': 'O'},
        {'b1': {'nodes': ('a1', 'a2')}}
    )
    a._add_node('a3', 'H')
    assert 'a3' in a.atoms
    assert a.atoms['a3'] == 'H'
Beispiel #2
0
def test_to_default():
    a = Molecule(
        {'a1': 'H', 'a2': 'O'},
        {'b1': {'nodes': ('a1', 'a2')}}
    )
    b = a.to_default()
    assert a == b
    assert a is b
Beispiel #3
0
def test_add_edge():
    a = Molecule(
        {'a1': 'H', 'a2': 'O'},
        {'b1': {'nodes': ('a1', 'a2')}}
    )
    a._add_edge('b2', {'nodes': ('a1', 'a2')})
    assert 'b2' in a.bonds
    assert a.bonds['b2'] == {'nodes': ('a1', 'a2'), 'id': 'b2'}
Beispiel #4
0
def test_add_existing_edge():
    a = Molecule({'a1': 'H', 'a2': 'O'}, {'b1': {'nodes': ('a1', 'a2')}})

    args = ['b1', {'nodes': ('a1', 'a2')}]
    function = a._add_edge
    exception_type = KeyError
    assert raises(exception_type, function, args)
Beispiel #5
0
def test_from_default():
    a = Molecule(
        {'a1': 'H', 'a2': 'O'},
        {'b1': {'nodes': ('a1', 'a2')}}
    )
    b = Molecule.from_default(a)
    assert a == b
    assert a is b
Beispiel #6
0
def test_simple_acid_base_reaction():
    acid = Molecule(
        {'a1': 'H', 'a2': 'H', 'a3': 'H', 'a4': 'O'},
        {'b1': {'nodes': ('a1', 'a4'), 'order': 1},
         'b2': {'nodes': ('a2', 'a4'), 'order': 1},
         'b3': {'nodes': ('a3', 'a4'), 'order': 1}
        },
        **{'id': 'Hydronium'}
    )

    base = Molecule(
        {'a1': 'H', 'a2': 'O'},
        {'b1': {'nodes': ('a1', 'a2'), 'order': 1}},
        **{'id': 'Hydroxide'}
    )

    conditions = {
        'pkas': {'Hydronium': -1.74, 'Hydroxide': 15.7},
        'pka_points': {'Hydronium': 'a1', 'Hydroxide': 'a2'}
    }

    products = react([acid, base], conditions)

    conjugate_acid = Molecule(
        {'a1': 'H', 'a2': 'H', 'a3': 'O'},
        {'b1': {'nodes': ('a1', 'a3'), 'order': 1},
         'b2': {'nodes': ('a2', 'a3'), 'order': 1}
        }
    )

    conjugate_base = Molecule(
        {'a1': 'H', 'a2': 'H', 'a3': 'O'},
        {'b1': {'nodes': ('a1', 'a3'), 'order': 1},
         'b2': {'nodes': ('a2', 'a3'), 'order': 1}
        }
    )

    assert products[0] == conjugate_acid
    assert products[1] == conjugate_base

    # Determining the salt isn't implemented
    assert products[2] is None
Beispiel #7
0
def test_add_node():
    a = Molecule({'a1': 'H', 'a2': 'O'}, {'b1': {'nodes': ('a1', 'a2')}})
    a._add_node('a3', 'H')
    assert 'a3' in a.atoms
    assert a.atoms['a3'] == 'H'
Beispiel #8
0
def test_from_default():
    a = Molecule({'a1': 'H', 'a2': 'O'}, {'b1': {'nodes': ('a1', 'a2')}})
    b = Molecule.from_default(a)
    assert a == b
    assert a is b
Beispiel #9
0
def test_simple_equality():
    a = Molecule({'a1': 'H', 'a2': 'O'}, {'b1': {'nodes': ('a1', 'a2')}})
    b = Molecule({'a1': 'H', 'a2': 'O'}, {'b1': {'nodes': ('a1', 'a2')}})

    assert a == b
Beispiel #10
0
def test_add_edge():
    a = Molecule({'a1': 'H', 'a2': 'O'}, {'b1': {'nodes': ('a1', 'a2')}})
    a._add_edge('b2', {'nodes': ('a1', 'a2')})
    assert 'b2' in a.bonds
    assert a.bonds['b2'] == {'nodes': ('a1', 'a2'), 'id': 'b2'}
Beispiel #11
0
def test_next_id_bond():
    a = Molecule({'a1': 'H', 'a2': 'O'}, {'b1': {'nodes': ('a1', 'a2')}})

    assert a._next_free_bond_id == 'b0'
Beispiel #12
0
def test_next_id_invalid():
    a = Molecule({'a1': 'H', 'a2': 'O'}, {'b1': {'nodes': ('a1', 'a2')}})

    assert raises(ValueError, a._next_id, ('c', ))
Beispiel #13
0
def test_next_id_atom():
    a = Molecule({'a1': 'H', 'a2': 'O'}, {'b1': {'nodes': ('a1', 'a2')}})

    assert a._next_free_atom_id == 'a0'
Beispiel #14
0
def test_stupid_repr_test():
    a = Molecule({'a1': 'H', 'a2': 'O'}, {'b1': {'nodes': ('a1', 'a2')}})

    assert repr(a)
Beispiel #15
0
def test_to_default():
    a = Molecule({'a1': 'H', 'a2': 'O'}, {'b1': {'nodes': ('a1', 'a2')}})
    b = a.to_default()
    assert a == b
    assert a is b
Beispiel #16
0
def test_inequality():
    a = Molecule({'a1': 'H', 'a2': 'O'}, {'b1': {'nodes': ('a1', 'a2')}})
    b = Molecule({'a1': 'N', 'a2': 'O'}, {'b1': {'nodes': ('a1', 'a2')}})

    assert a != b
Beispiel #17
0
def test_isomorphic_equality():
    a = Molecule({'a1': 'H', 'a2': 'O'}, {'b1': {'nodes': ('a1', 'a2')}})
    b = Molecule({'a2': 'H', 'a1': 'O'}, {'b2': {'nodes': ('a1', 'a2')}})

    assert a == b