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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2015-04-29 23:44:49 UTC
  • mfrom: (5.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20150429234449-mbhy9utku6hp6oq8
Tags: 0~20150313.gitfa668e1-1
Upload into unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
143
143
from nbody_by_type_lib import GenInteractions_str
144
144
from ttree_lex import *
145
145
from lttree_styles import AtomStyle2ColNames, ColNames2AidAtypeMolid
146
 
 
 
146
import os, inspect # <- Needed to import modules in subdirectories (see below)
147
147
 
148
148
if sys.version < '2.6':
149
149
    raise InputError('Error: Using python '+sys.version+'\n'
337
337
        f.close()
338
338
 
339
339
 
340
 
    g = __import__(src_bond_pattern) #defines g.bond_pattern, g.canonical_order
 
340
    try:
 
341
        g = __import__(src_bond_pattern) #defines g.bond_pattern, g.canonical_order
 
342
    except:
 
343
        # If not found, look for it in the "nbody_alternate_symmetry" directory
 
344
        #http://stackoverflow.com/questions/279237/import-a-module-from-a-relative-path
 
345
        cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"nbody_alternate_symmetry")))
 
346
        if cmd_subfolder not in sys.path:
 
347
            sys.path.insert(0, cmd_subfolder)
 
348
        try:
 
349
            g = __import__(src_bond_pattern) #defines g.bond_pattern, g.canonical_order
 
350
        except:
 
351
            sys.stderr.write('Error: Unable to locate file \"'+src_bond_pattern+'\"\n'
 
352
                             '       (Did you mispell the file name?\n'
 
353
                             '        Check the \"nbody_alternate_symmetry/\" directory.)\n')
 
354
            sys.exit(-1)
 
355
        
 
356
 
341
357
 
342
358
 
343
359
    return GenInteractions_lines(lines_atoms,
359
375
if __name__ == "__main__":
360
376
 
361
377
    g_program_name = __file__.split('/')[-1]  # = 'nbody_by_type.py'
362
 
    g_date_str     = '2014-4-07'
363
 
    g_version_str  = '0.16'
 
378
    g_date_str     = '2014-12-19'
 
379
    g_version_str  = '0.18'
 
380
 
 
381
    bond_pattern_module_name = ""
364
382
 
365
383
    #######  Main Code Below: #######
366
384
    sys.stderr.write(g_program_name+' v'+g_version_str+' '+g_date_str+' ')
474
492
                                     '       (See nbody_Dihedrals.py for example.)\n')
475
493
                bond_pattern_module_name = argv[i+1]
476
494
                # If the file name ends in ".py", then strip off this suffix.
477
 
                bond_pattern_module_name=bond_pattern_module_name.rstrip('.py')
 
495
                # For some reason, the next line does not work:
 
496
                #bond_pattern_module_name=bond_pattern_module_name.rstrip('.py')
 
497
                # Do this instead
 
498
                pc = bond_pattern_module_name.rfind('.py')
 
499
                if pc != -1:
 
500
                    bond_pattern_module_name = bond_pattern_module_name[0:pc]
 
501
 
478
502
                del(argv[i:i+2])
479
503
 
480
504
            elif argv[i].lower() == '-section':
516
540
        elif len(argv) == 2:
517
541
            section_name = argv[1]
518
542
            section_name_bytype = section_name + ' By Type'
519
 
            bond_pattern_module_name = 'nbody_'+section_name
 
543
            # default bond_pattern_module name
 
544
            if bond_pattern_module_name == "":  #<--if not set by user
 
545
                bond_pattern_module_name = 'nbody_'+section_name
520
546
            del(argv[1:2])
521
547
        else:
522
548
            # if there are more than 2 remaining arguments,