Example #1
0
def test_multiframe_file():
    p = XYZParser()
    expected = [ { 'natoms': 5,
            'comment': 'i =        1, E =        -8.0633022872',
            'atoms': [
                ('C', (5.0, 5.0, 5.0)),
                ('H', (5.6401052216, 5.6401052216, 5.6401052216)),
                ('H', (4.3598947806, 4.3598947806, 5.6401052208)),
                ('H', (4.3598947806, 5.6401052208, 4.3598947806)),
                ('H', (5.6401052208, 4.3598947806, 4.3598947806)) ] },
            { 'natoms': 5,
            'comment': 'i =        2, E =        -8.0633022874',
            'atoms': [
                ('C', (5.0, 5.0, 5.0)),
                ('H', (5.6401902064, 5.6401902064, 5.6401902064)),
                ('H', (4.3598097942, 4.3598097942, 5.6401902063)),
                ('H', (4.3598097942, 5.6401902063, 4.3598097942)),
                ('H', (5.6401902063, 4.3598097942, 4.3598097942)) ] },
            { 'natoms': 5,
            'comment': 'i =        3, E =        -8.0632890314',
            'atoms': [
                ('C', (5.0, 5.0, 5.0)),
                ('H', (5.6401902064, 5.6401902064, 5.6401902064)),
                ('H', (4.3598097942, 4.3598097942, 5.6401902063)),
                ('H', (4.3598097942, 5.6401902063, 4.3598097942)),
                ('H', (5.6401902063, 4.3598097942, 4.3598097942)) ] } ]
    with open('tests/test_xyz_parser-simple_multiframe_file.xyz', 'r') as f:
        assert expected == p.parse(f)
def test_multiframe_file():
    p = XYZParser()
    expected = [{
        'natoms':
        5,
        'comment':
        'i =        1, E =        -8.0633022872',
        'atoms': [('C', (5.0, 5.0, 5.0)),
                  ('H', (5.6401052216, 5.6401052216, 5.6401052216)),
                  ('H', (4.3598947806, 4.3598947806, 5.6401052208)),
                  ('H', (4.3598947806, 5.6401052208, 4.3598947806)),
                  ('H', (5.6401052208, 4.3598947806, 4.3598947806))]
    }, {
        'natoms':
        5,
        'comment':
        'i =        2, E =        -8.0633022874',
        'atoms': [('C', (5.0, 5.0, 5.0)),
                  ('H', (5.6401902064, 5.6401902064, 5.6401902064)),
                  ('H', (4.3598097942, 4.3598097942, 5.6401902063)),
                  ('H', (4.3598097942, 5.6401902063, 4.3598097942)),
                  ('H', (5.6401902063, 4.3598097942, 4.3598097942))]
    }, {
        'natoms':
        5,
        'comment':
        'i =        3, E =        -8.0632890314',
        'atoms': [('C', (5.0, 5.0, 5.0)),
                  ('H', (5.6401902064, 5.6401902064, 5.6401902064)),
                  ('H', (4.3598097942, 4.3598097942, 5.6401902063)),
                  ('H', (4.3598097942, 5.6401902063, 4.3598097942)),
                  ('H', (5.6401902063, 4.3598097942, 4.3598097942))]
    }]
    with open('tests/test_xyz_parser-simple_multiframe_file.xyz', 'r') as f:
        assert expected == p.parse(f)
Example #3
0
def test_singleframe_string():
    p = XYZParser()
    s = '''
5

C 5.0000000000 5.0000000000 5.0000000000
H 5.6401902064 5.6401902064 5.6401902064
H 4.3598097942 4.3598097942 5.6401902063
H 4.3598097942 5.6401902063 4.3598097942
H 5.6401902063 4.3598097942 4.3598097942
'''
    expected = [ { 'natoms': 5, 'comment': '',
            'atoms': [
                ('C', (5.0, 5.0, 5.0)),
                ('H', (5.6401902064, 5.6401902064, 5.6401902064)),
                ('H', (4.3598097942, 4.3598097942, 5.6401902063)),
                ('H', (4.3598097942, 5.6401902063, 4.3598097942)),
                ('H', (5.6401902063, 4.3598097942, 4.3598097942)) ] } ]

    assert expected == p.parse(s)
def test_singleframe_string():
    p = XYZParser()
    s = '''
5

C 5.0000000000 5.0000000000 5.0000000000
H 5.6401902064 5.6401902064 5.6401902064
H 4.3598097942 4.3598097942 5.6401902063
H 4.3598097942 5.6401902063 4.3598097942
H 5.6401902063 4.3598097942 4.3598097942
'''
    expected = [{
        'natoms':
        5,
        'comment':
        '',
        'atoms': [('C', (5.0, 5.0, 5.0)),
                  ('H', (5.6401902064, 5.6401902064, 5.6401902064)),
                  ('H', (4.3598097942, 4.3598097942, 5.6401902063)),
                  ('H', (4.3598097942, 5.6401902063, 4.3598097942)),
                  ('H', (5.6401902063, 4.3598097942, 4.3598097942))]
    }]

    assert expected == p.parse(s)