Skip to content

Commit

Permalink
Merge pull request #166 from marrink-lab/test-molecule-layout
Browse files Browse the repository at this point in the history
Bring the formatting of test_molecule in line with the rest
  • Loading branch information
jbarnoud committed Jan 19, 2019
2 parents 7ee3771 + 5deed6a commit 3af8756
Showing 1 changed file with 71 additions and 41 deletions.
112 changes: 71 additions & 41 deletions vermouth/tests/test_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,43 +48,62 @@ def molecule_copy(molecule):


@pytest.mark.parametrize('atoms, bonds, interactions, removed, expected', [
# empty molecule
([], [], [], [], {}),
# Nodes but no interactions
([1, 2, 3], [(1, 2), (2, 3)], [], [2], {}),
# interactions that all need to be removed
([1, 2], [(1, 2)], [('bond', (1, 2), {})], [2], {}),
# Molecule with interactions of which some need to be removed
([1, 2, 3, 4, 5, 6, 7], [(1, 2), (3, 4), (5, 7)], [('bond', (5, 4), {}), ('bond', (1, 2), {})], [5]
, {'bond': [vermouth.molecule.Interaction(atoms=(1, 2), meta={}, parameters={})]}),
(
[1, 2, 3, 4, 5, 6, 7],
[(1, 2), (3, 4), (5, 7)],
[('bond', (5, 4), {}), ('bond', (1, 2), {})],
[5],
{'bond': [vermouth.molecule.Interaction(atoms=(1, 2), meta={}, parameters={})]}
),
# Molecule with interactions of which none need to be removed
([1, 2, 3, 4, 5, 6, 7], [(1, 2), (3, 4)], [('bond', (5, 4), {}), ('bond', (1, 2), {})], [6, 7]
, {'bond': [vermouth.molecule.Interaction(atoms=(5, 4), meta={}, parameters={})
, vermouth.molecule.Interaction(atoms=(1, 2), meta={}, parameters={})]}),
(
[1, 2, 3, 4, 5, 6, 7],
[(1, 2), (3, 4)],
[('bond', (5, 4), {}), ('bond', (1, 2), {})],
[6, 7],
{'bond': [vermouth.molecule.Interaction(atoms=(5, 4), meta={}, parameters={}),
vermouth.molecule.Interaction(atoms=(1, 2), meta={}, parameters={})]}
),
# Molecule with interactions of different types of which all need to be removed
([1, 2, 3, 4, 5, 6, 7], [(1, 2), (3, 4), (5, 7), (6, 7)], [('bond', (1, 6), {}), ('bond', (5, 4), {})
, ('angle', (1, 2), {})], [1, 5], {}),
(
[1, 2, 3, 4, 5, 6, 7],
[(1, 2), (3, 4), (5, 7), (6, 7)],
[('bond', (1, 6), {}), ('bond', (5, 4), {}), ('angle', (1, 2), {})],
[1, 5],
{}
),
# Molecule with interactions of different types of which some need to be removed
([1, 2, 3, 4, 5, 6, 7], [(1, 2), (3, 4), (5, 7), (6, 7)]
, [('bond', (1, 6), {}), ('bond', (5, 4), {}), ('angle', (1, 2), {})], [5]
, {'angle': [vermouth.molecule.Interaction(atoms=(1, 2), meta={}, parameters={})]
, 'bond': [vermouth.molecule.Interaction(atoms=(1, 6), meta={}, parameters={})]}),
(
[1, 2, 3, 4, 5, 6, 7],
[(1, 2), (3, 4), (5, 7), (6, 7)],
[('bond', (1, 6), {}), ('bond', (5, 4), {}), ('angle', (1, 2), {})],
[5],
{'angle': [vermouth.molecule.Interaction(atoms=(1, 2), meta={}, parameters={})],
'bond': [vermouth.molecule.Interaction(atoms=(1, 6), meta={}, parameters={})]}
),
# Molecule with interactions of different types of which none need to be removed
([1, 2, 3, 4, 5, 6, 7], [(1, 2), (3, 4), (5, 7), (6, 7)]
, [('bond', (1, 6), {}), ('bond', (5, 4), {}), ('angle', (1, 2), {})], [3]
, {'angle': [vermouth.molecule.Interaction(atoms=(1, 2), meta={}, parameters={})]
, 'bond': [vermouth.molecule.Interaction(atoms=(1, 6), meta={}, parameters={})
, vermouth.molecule.Interaction(atoms=(5, 4), meta={}, parameters={})]}),
(
[1, 2, 3, 4, 5, 6, 7],
[(1, 2), (3, 4), (5, 7), (6, 7)],
[('bond', (1, 6), {}), ('bond', (5, 4), {}), ('angle', (1, 2), {})],
[3],
{'angle': [vermouth.molecule.Interaction(atoms=(1, 2), meta={}, parameters={})],
'bond': [vermouth.molecule.Interaction(atoms=(1, 6), meta={}, parameters={}),
vermouth.molecule.Interaction(atoms=(5, 4), meta={}, parameters={})]}
),
])
def test_remove_nodes_from(atoms, bonds, interactions, removed, expected):
"""
Test whether molecule.remove_nodes_from also removes the corresponding
interactions
"""
molecule = vermouth.molecule.Molecule()
molecule.add_nodes_from(atoms)
molecule.add_edges_from(bonds)
Expand All @@ -96,34 +115,45 @@ def test_remove_nodes_from(atoms, bonds, interactions, removed, expected):


@pytest.mark.parametrize('atoms, bonds, interactions, removed, expected', [
# empty molecule
([], [], [], None, {}),
# Nodes but no interactions
([1, 2, 3], [(1, 2), (2, 3)], [], 2, {}),
# interactions that all need to be removed
([1, 2], [(1, 2)], [('bond', (1, 2), {})], 2, {}),
# Molecule with interactions of which some need to be removed
([1, 2, 3, 4, 5, 6, 7], [(1, 2), (3, 4), (5, 7)], [('bond', (5, 4), {}), ('bond', (1, 2), {})], 5
, {'bond': [vermouth.molecule.Interaction(atoms=(1, 2), meta={}, parameters={})]}),
(
[1, 2, 3, 4, 5, 6, 7],
[(1, 2), (3, 4), (5, 7)],
[('bond', (5, 4), {}), ('bond', (1, 2), {})],
5,
{'bond': [vermouth.molecule.Interaction(atoms=(1, 2), meta={}, parameters={})]}
),
# Molecule with interactions of different types of which some need to be removed
([1, 2, 3, 4, 5, 6, 7], [(1, 2), (3, 4), (5, 7), (6, 7)]
, [('bond', (1, 6), {}), ('bond', (5, 4), {}), ('angle', (1, 2), {})], 5
, {'angle': [vermouth.molecule.Interaction(atoms=(1, 2), meta={}, parameters={})],
'bond': [vermouth.molecule.Interaction(atoms=(1, 6), meta={}, parameters={})]}),
(
[1, 2, 3, 4, 5, 6, 7],
[(1, 2), (3, 4), (5, 7), (6, 7)],
[('bond', (1, 6), {}), ('bond', (5, 4), {}), ('angle', (1, 2), {})],
5,
{'angle': [vermouth.molecule.Interaction(atoms=(1, 2), meta={}, parameters={})],
'bond': [vermouth.molecule.Interaction(atoms=(1, 6), meta={}, parameters={})]}
),
# Molecule with interactions of different types of which none need to be removed
([1, 2, 3, 4, 5, 6, 7], [(1, 2), (3, 4), (5, 7), (6, 7)]
, [('bond', (1, 6), {}), ('bond', (5, 4), {}), ('angle', (1, 2), {})], 3
, {'angle': [vermouth.molecule.Interaction(atoms=(1, 2), meta={}, parameters={})],
'bond': [vermouth.molecule.Interaction(atoms=(1, 6), meta={}, parameters={})
, vermouth.molecule.Interaction(atoms=(5, 4), meta={}, parameters={})]}),
(
[1, 2, 3, 4, 5, 6, 7],
[(1, 2), (3, 4), (5, 7), (6, 7)],
[('bond', (1, 6), {}), ('bond', (5, 4), {}), ('angle', (1, 2), {})],
3,
{'angle': [vermouth.molecule.Interaction(atoms=(1, 2), meta={}, parameters={})],
'bond': [vermouth.molecule.Interaction(atoms=(1, 6), meta={}, parameters={}),
vermouth.molecule.Interaction(atoms=(5, 4), meta={}, parameters={})]}
),
])
def test_remove_node(atoms, bonds, interactions, removed, expected):
"""
Test whether molecule.remove_node also removes the corresponding
interactions
"""
molecule = vermouth.molecule.Molecule()
molecule.add_nodes_from(atoms)
molecule.add_edges_from(bonds)
Expand Down

0 comments on commit 3af8756

Please sign in to comment.