Skip to content

Commit

Permalink
Merge pull request #440 from ReactionMechanismGenerator/AddTest_speci…
Browse files Browse the repository at this point in the history
…es_xyz_to_2d_get_formula

Add unit test for MolGraph.get_formula after fixing bug in same
  • Loading branch information
alongd committed Dec 25, 2020
2 parents 20e68d2 + d91f074 commit 747756b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion arc/species/speciesTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
check_xyz,
determine_rotor_symmetry,
determine_rotor_type)

from arc.species.xyz_to_2d import MolGraph

class TestARCSpecies(unittest.TestCase):
"""
Expand Down Expand Up @@ -1375,6 +1375,18 @@ def test_from_dict(self):
self.assertEqual(tsg.method, 'autotst')
self.assertTrue(isinstance(tsg.rmg_reaction, Reaction))

def test_xyz_to_2d_get_formula(self):
xyz_arb = {'symbols': ('H', 'C', 'H', 'H', 'O', 'N', 'O'),
'isotopes': (1, 13, 1, 1, 16, 14, 16),
'coords': ((-1.0, 0.0, 0.0),
(0.0, 0.0, 0.0),
(0.0, -1.0, 0.0),
(0.0, 1.0, 0.0),
(1.0, 0.0, 0.0),
(2.0, 0.0, 0.0),
(3.0, 0.0, 0.0),)}
mol_graph_1 = MolGraph(symbols=xyz_arb['symbols'], coords=xyz_arb['coords'])
self.assertEqual(mol_graph_1.get_formula(), 'CH3NO2')

if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
4 changes: 2 additions & 2 deletions arc/species/xyz_to_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class Atom(object):
"""
Represents an atopm in a molecular graph.
Represents an atom in a molecular graph.
"""

def __init__(self, symbol=None, idx=None, coords=np.array([]), frozen=False):
Expand Down Expand Up @@ -150,7 +150,7 @@ def get_formula(self):
count = elements['H']
formula += 'H{:d}'.format(count) if count > 1 else 'H'
del elements['H']
keys = elements.keys()
keys = list(elements.keys())
keys.sort()
for key in keys:
count = elements[key]
Expand Down

0 comments on commit 747756b

Please sign in to comment.