~ubuntu-branches/debian/sid/lammps/sid

« back to all changes in this revision

Viewing changes to tools/moltemplate/src/lttree_check.py

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2013-11-20 22:41:36 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20131120224136-tzx7leh606fqnckm
Tags: 0~20131119.git7162cf0-1
* [e65b919] Imported Upstream version 0~20131119.git7162cf0
* [f7bddd4] Fix some problems, introduced by upstream recently.
* [3616dfc] Use wrap-and-sort script.
* [7e92030] Ignore quilt dir

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
from lttree import *
49
49
from ttree_lex import InputError
50
50
 
51
 
if sys.version < '2.6':
 
51
if sys.version < '2.7':
52
52
    raise InputError('Error: Alas, you must upgrade to a newever version of python.')
53
53
 
54
54
 
434
434
                             'You should probably use write_once(\"'+filename+'\") instead.\n')
435
435
 
436
436
 
 
437
    elif ((section_name.lower() == 'bonds by type') or
 
438
          (section_name.lower() == 'bonds bytype') or          
 
439
          (section_name.lower() == 'bonds_by_type') or
 
440
          (section_name.lower() == 'bonds_bytype') or
 
441
          (section_name.lower() == 'bondsbytype') or
 
442
          (section_name.lower() == 'bond by type') or
 
443
          (section_name.lower() == 'bond bytype') or          
 
444
          (section_name.lower() == 'bond_by_type') or
 
445
          (section_name.lower() == 'bond_bytype') or
 
446
          (section_name.lower() == 'bondbytype')):
 
447
        if (filename != data_bonds_by_type):
 
448
            raise InputError('Probable typo in '+ErrorLeader(srcloc.infile,srcloc.lineno)+'\n\n'+
 
449
                             'Output file name (\"'+filename+'\") does not match,\n'
 
450
                             'yet overlaps closely with reserved lttree-file name.\n'
 
451
                             'Perhaps you meant \"'+data_bonds_by_type+'\"?')
 
452
        elif (write_command != 'write_once'):
 
453
            raise InputError('Probable typo in '+ErrorLeader(srcloc.infile,srcloc.lineno)+'\n\n'+
 
454
                             'When using moltemplate.sh to build LAMMPS input files, you probably do not\n'
 
455
                             'want to use the '+write_command+'() command with \"'+filename+'\".\n'
 
456
                             'You should probably use write_once(\"'+filename+'\") instead.\n')
 
457
 
 
458
 
437
459
 
438
460
    elif ((section_name.lower() == 'angles by type') or
439
461
          (section_name.lower() == 'angles bytype') or          
514
536
                             'want to use the '+write_command+'() command with \"'+filename+'\".\n'
515
537
                             'You should probably use write(\"'+filename+'\") instead.\n')
516
538
 
 
539
    elif ((section_name.lower().find('bond list') == 0) or
 
540
          (section_name.lower().find('bonds list') == 0) or
 
541
          (section_name.lower().find('bond_list') == 0) or
 
542
          (section_name.lower().find('bonds_list') == 0)):
 
543
        if (filename != data_bond_list):
 
544
            raise InputError('Probable typo in '+ErrorLeader(srcloc.infile,srcloc.lineno)+'\n\n'+
 
545
                             'Output file name (\"'+filename+'\") does not match,\n'
 
546
                             'yet overlaps closely with reserved lttree-file name.\n'
 
547
                             'Perhaps you meant \"'+data_bonds_by_type+'\"?')
 
548
        elif (write_command != 'write'):
 
549
            raise InputError('Probable typo in '+ErrorLeader(srcloc.infile,srcloc.lineno)+'\n\n'+
 
550
                             'When using moltemplate.sh to build LAMMPS input files, you probably do not\n'
 
551
                             'want to use the '+write_command+'() command with \"'+filename+'\".\n'
 
552
                             'You should probably use write(\"'+filename+'\") instead.\n')
 
553
 
 
554
 
517
555
    elif ((section_name.lower() == 'angles') or
518
556
          (section_name.lower() == 'angle')):
519
557
        if (filename != data_angles):
975
1013
                                                 g_no_check_msg)
976
1014
 
977
1015
 
 
1016
            elif filename == 'Data Bond List':
 
1017
                table = TableFromTemplate(command.tmpl_list,
 
1018
                                          [[' ', '\t', '\r'], '\n'],
 
1019
                                          [True, False])
 
1020
                for i in range(0, len(table)):
 
1021
                    syntax_err = False
 
1022
                    assert(hasattr(table[i], '__len__'))
 
1023
                    if len(table[i]) > 0:
 
1024
                        if ((len(table[i]) > 1) and
 
1025
                            isinstance(table[i][0], TextBlock) and
 
1026
                            (len(table[i][0].text) > 0) and
 
1027
                            (table[i][0].text == '#')):
 
1028
                            pass
 
1029
                        else:
 
1030
                            if len(table[i]) < 3:
 
1031
                                syntax_err = True
 
1032
                            table_entry = table[i][0]
 
1033
                            if (not ((isinstance(table_entry, VarRef)) and
 
1034
                                     (table_entry.prefix in ('$','${')) and
 
1035
                                     (ExtractCatName(table_entry.descr_str) == 'bond'))):
 
1036
                                syntax_err = True
 
1037
                            if len(table[i]) > 1:
 
1038
                                table_entry = table[i][1]
 
1039
                            if (not ((isinstance(table_entry, VarRef)) and
 
1040
                                     (table_entry.prefix in ('$','${')) and
 
1041
                                     (ExtractCatName(table_entry.descr_str) == 'atom'))):
 
1042
                                syntax_err = True
 
1043
                            if len(table[i]) > 2:
 
1044
                                table_entry = table[i][2]
 
1045
                            if (not ((isinstance(table_entry, VarRef)) and
 
1046
                                     (table_entry.prefix in ('$','${')) and
 
1047
                                     (ExtractCatName(table_entry.descr_str) == 'atom'))):
 
1048
                                syntax_err = True
 
1049
 
 
1050
                            if syntax_err:
 
1051
                                raise InputError('----------------------------------------------------\n'+
 
1052
                                                 '     Syntax error near '+
 
1053
                                                 ErrorLeader(table[i][0].srcloc.infile,
 
1054
                                                             table[i][0].srcloc.lineno)+'\n'
 
1055
                                                 '     Incorrect "Data Bond List" syntax.\n'+
 
1056
                                                 'Each lines in this section should have this format:\n\n'
 
1057
                                                 '  $bond:id $atom:id1 $atom:id2\n'+
 
1058
                                                 '----------------------------------------------------\n'+
 
1059
                                                 g_no_check_msg)
 
1060
 
 
1061
 
978
1062
            elif filename == 'Data Angles':
979
1063
                table = TableFromTemplate(command.tmpl_list,
980
1064
                                          [[' ', '\t', '\r'], '\n'],
1399
1483
                                                      table[i][0].binding))
1400
1484
 
1401
1485
 
 
1486
            elif filename == 'Data Bonds By Type':
 
1487
                table = TableFromTemplate(command.tmpl_list,
 
1488
                                          [[' ','\t','\r'], '\n'],
 
1489
                                          [True, False])
 
1490
                for i in range(0, len(table)):
 
1491
                    if len(table[i]) == 0:
 
1492
                        pass
 
1493
                    elif ((len(table[i]) > 1) and
 
1494
                          isinstance(table[i][0], TextBlock) and
 
1495
                          (len(table[i][0].text) > 0) and
 
1496
                          (table[i][0].text == '#')):
 
1497
                        pass #Ignore comment lines (postprocessing removes them)
 
1498
                    elif (not ((len(table[i]) >= 3) and
 
1499
                               isinstance(table[i][0], VarRef) and
 
1500
                               (table[i][0].prefix in ('@', '@{')) and 
 
1501
                               (table[i][0].nptr.cat_name == 'bond') and
 
1502
                               (table[i][0].nptr.cat_node == root_node))):
 
1503
                        raise InputError('----------------------------------------------------\n'+
 
1504
                                         '     Syntax error near '+
 
1505
                                         ErrorLeader(table[i][0].srcloc.infile,
 
1506
                                                     table[i][0].srcloc.lineno)+'\n'
 
1507
                                         '     Incorrect \"Data Bonds By Type\" syntax.\n'
 
1508
                                         '  Each line of the \"Data Bonds By Type\" section should begin with an\n'
 
1509
                                         '  @bond:type variable followed by 2 atom types.\n'+
 
1510
                                         '----------------------------------------------------\n'+
 
1511
                                         g_no_check_msg)
 
1512
 
 
1513
 
1402
1514
            elif filename == 'Data Angles By Type':
1403
1515
                table = TableFromTemplate(command.tmpl_list,
1404
1516
                                          [[' ','\t','\r'], '\n'],
1813
1925
        else:
1814
1926
            # if there are more than 2 remaining arguments,
1815
1927
            problem_args = ['\"'+arg+'\"' for arg in argv[1:]]
1816
 
            raise InputError('Syntax Error('+__file__+'):\n\n'
 
1928
            raise InputError('Syntax Error('+g_program_name+'):\n\n'
1817
1929
                             '       Unrecognized argument.\n'
1818
1930
                             '         (That or there is some other problem with the argument list.)\n'
1819
1931
                             '       The problem begins with these arguments:\n'
1832
1944
 
1833
1945
if __name__ == "__main__":
1834
1946
 
1835
 
    g_program_name = 'lttree_check.py'
1836
 
    g_version_str  = '0.72'
1837
 
    g_date_str     = '2012-12-15'
 
1947
    g_program_name = __file__.split('/')[-1]  # = 'lttree_check.py'
 
1948
    g_version_str  = '0.73'
 
1949
    g_date_str     = '2013-8-06'
1838
1950
    sys.stderr.write(g_program_name+' v'+g_version_str+' '+g_date_str+'\n')
1839
1951
 
1840
1952
    try: