示例#1
0
def check_lmps_attr(s):
    # sync of the forcefield-style properties
    if hasattr(s, 'forcefield'):
        styles_list = FF_SETTINGS['dreiding'].keys()
        if s.forcefield in FF_SETTINGS.keys():
            for st_prop in styles_list:
                setattr(s, st_prop, FF_SETTINGS[s.forcefield][st_prop])
        else:
            warning_print('Cannot synchronize given forcefield with LAMMPS representation types. '
                          'The forcefield is not present in the FF_SETTINGS of the pysimm.lmps module')
    else:
        warning_print('The forcefield attribute of the system is not defined. Some i/o methods of lmps '
                      'module will not be acessible')
示例#2
0
def call_lammps(simulation, np, nanohub, prefix='mpiexec'):
    """pysimm.lmps.call_lammps

    Wrapper to call LAMMPS using executable name defined in pysimm.lmps module.

    Args:
        simulation: :class:`~pysimm.lmps.Simulation` object reference
        np: number of threads to use
        nanohub: dictionary containing nanohub resource information default=None
        prefix: prefix for running LAMMPS (i.e. - mpiexec)

    Returns:
        None
    """

    log_name = simulation.log or 'log.lammps'

    if nanohub:
        with open('temp.in', 'w') as f:
            f.write(simulation.input)
        if simulation.name:
            print('%s: sending %s simulation to computer cluster at nanoHUB' %
                  (strftime('%H:%M:%S'), simulation.name))
        else:
            print('%s: sending simulation to computer cluster at nanoHUB' %
                  strftime('%H:%M:%S'))
        sys.stdout.flush()
        cmd = ('submit -n %s -w %s -i temp.lmps -i temp.in '
               'lammps-09Dec14-parallel -e both -l none -i temp.in' %
               (nanohub.get('cores'), nanohub.get('walltime')))
        cmd = shlex.split(cmd)
        exit_status, stdo, stde = RapptureExec(cmd)
    else:
        if simulation.name:
            print('%s: starting %s LAMMPS simulation' %
                  (strftime('%H:%M:%S'), simulation.name))
        else:
            print('%s: starting LAMMPS simulation' % strftime('%H:%M:%S'))
        if np:
            p = Popen([prefix, '-np',
                       str(np), LAMMPS_EXEC, '-e', 'both'],
                      stdin=PIPE,
                      stdout=PIPE,
                      stderr=PIPE)
        else:
            p = Popen([LAMMPS_EXEC, '-e', 'both'],
                      stdin=PIPE,
                      stdout=PIPE,
                      stderr=PIPE)
        simulation.write_input()
        if simulation.debug:
            print(simulation.input)
            warning_print(
                'debug setting involves streaming output from LAMMPS process and can degrade performance'
            )
            warning_print(
                'only use debug for debugging purposes, use print_to_screen to collect stdout after process finishes'
            )
            p.stdin.write(simulation.input.encode('utf-8'))
            q = Queue()
            t = Thread(target=enqueue_output, args=(p.stdout, q))
            t.daemon = True
            t.start()

            while t.is_alive() or not q.empty():
                try:
                    line = q.get_nowait()
                except Empty:
                    pass
                else:
                    if simulation.debug:
                        sys.stdout.write(line.decode('utf-8'))
                        sys.stdout.flush()
        else:
            stdo, stde = p.communicate(simulation.input.encode('utf-8'))
            if simulation.print_to_screen:
                print(stdo.decode('utf-8'))
                print(stde.decode('utf-8'))

    simulation.system.read_lammps_dump('pysimm.dump.tmp')

    try:
        os.remove('temp.lmps')
    except OSError as e:
        print(str(e))

    if os.path.isfile('pysimm.qeq.tmp'):
        os.remove('pysimm.qeq.tmp')

    try:
        os.remove('pysimm.dump.tmp')
        if simulation.name:
            print('%s: %s simulation using LAMMPS successful' %
                  (strftime('%H:%M:%S'), simulation.name))
        else:
            print('%s: simulation using LAMMPS successful' %
                  (strftime('%H:%M:%S')))
    except OSError as e:
        if simulation.name:
            raise PysimmError('%s simulation using LAMMPS UNsuccessful' %
                              simulation.name)
        else:
            raise PysimmError('simulation using LAMMPS UNsuccessful')