Ejemplo n.º 1
0
def test_write_splash():
    from nexus_base import NexusCore
    log = divert_nexus_log()
    nc = NexusCore()
    assert(not nc.wrote_splash)
    nc.write_splash()
    assert('Nexus' in log.contents())
    assert('Please cite:' in log.contents())
    assert(nc.wrote_splash)
    restore_nexus_log()
Ejemplo n.º 2
0
 def run_project(self, status=False, status_only=False):
     self.log('\nProject starting', n=0)
     self.init_cascades()
     status_only = status_only or nexus_core.status_only
     status = status or status_only or nexus_core.status != nexus_core.status_modes.none
     if status:
         self.write_simulation_status()
         if status_only:
             NexusCore.write_end_splash()
             return
         #end if
     #end if
     self.log('\nstarting runs:\n' + 30 * '~', n=1)
     if nexus_core.dependent_modes <= nexus_core.stages_set:
         if nexus_core.monitor:
             start_time = time.time()
             ipoll = 0
             while len(self.progressing_cascades) > 0:
                 elapsed_time = time.time() - start_time
                 self.log('elapsed time %.1f s' % elapsed_time,
                          ' memory %3.2f MB' %
                          (memory.resident(children=True) / 1e6),
                          n=1,
                          progress=True)
                 NexusCore.wrote_something = False
                 ipoll += 1
                 self.machine.query_queue()
                 self.progress_cascades()
                 self.machine.submit_jobs()
                 self.update_process_ids()
                 time.sleep(nexus_core.sleep)
                 if NexusCore.wrote_something:
                     self.log()
                 #end if
             #end while
         elif len(self.progressing_cascades) > 0:
             self.machine.query_queue()
             self.progress_cascades()
             self.machine.submit_jobs()
             self.update_process_ids()
         #end if
     else:
         self.progress_cascades()
     #end if
     self.log('Project finished\n')
     NexusCore.write_end_splash()
Ejemplo n.º 3
0
 def run_project(self,status=False,status_only=False):
     self.log('\nProject starting',n=0)
     self.init_cascades()
     status_only = status_only or nexus_core.status_only
     status = status or status_only
     if status:
         self.write_simulation_status()
         if status_only:
             NexusCore.write_end_splash()
             return
         #end if
     #end if
     self.log('\nstarting runs:\n'+30*'~',n=1)
     if nexus_core.dependent_modes <= nexus_core.stages_set:
         if nexus_core.monitor:
             ipoll = 0
             while len(self.progressing_cascades)>0:
                 #self.log('poll',ipoll,' memory %3.2f MB'%(memory.resident()/1e6),n=1)
                 NexusCore.wrote_something = False
                 ipoll+=1
                 self.machine.query_queue()
                 self.progress_cascades()
                 self.machine.submit_jobs()
                 self.update_process_ids()
                 time.sleep(nexus_core.sleep)
                 if NexusCore.wrote_something:
                     self.log()
                 #end if
             #end while
         elif len(self.progressing_cascades)>0:
             self.machine.query_queue()
             self.progress_cascades()
             self.machine.submit_jobs()
             self.update_process_ids()
         #end if
     else:
         self.progress_cascades()
     #end if
     self.log('Project finished\n')
     NexusCore.write_end_splash()
Ejemplo n.º 4
0
def test_enter_leave():
    import os
    from nexus_base import NexusCore

    tpath = testing.setup_unit_test_output_directory('nexus_base','test_enter_leave')

    cwd = os.getcwd()

    log = divert_nexus_log()

    nc = NexusCore()

    nc.enter(tpath)
    tcwd = os.getcwd()
    assert(tcwd==tpath)
    assert('Entering' in log.contents())
    assert(tpath in log.contents())

    nc.leave()
    assert(os.getcwd()==cwd)

    restore_nexus_log()
Ejemplo n.º 5
0
    def __call__(self,**kwargs):

        NexusCore.write_splash()

        self.log('Applying user settings')

        # guard against invalid settings
        not_allowed = set(kwargs.keys()) - Settings.allowed_vars
        if len(not_allowed)>0:
            self.error('unrecognized variables provided.\nYou provided: {0}\nAllowed variables are: {1}'.format(sorted(not_allowed),sorted(Settings.allowed_vars)))
        #end if

        # assign simple variables
        for name in Settings.core_assign_vars:
            if name in kwargs:
                nexus_core[name] = kwargs[name]
            #end if
        #end for

        # assign simple variables
        for name in Settings.noncore_assign_vars:
            if name in kwargs:
                nexus_noncore[name] = kwargs[name]
            #end if
        #end for

        # extract settings based on keyword groups
        kw        = Settings.kw_set(Settings.nexus_vars  ,kwargs)   
        mach_kw   = Settings.kw_set(Settings.machine_vars,kwargs)      
        gamess_kw = Settings.kw_set(Settings.gamess_vars ,kwargs)       
        if len(kwargs)>0:
            self.error('some settings keywords have not been accounted for\nleftover keywords: {0}\nthis is a developer error'.format(sorted(kwargs.keys())))
        #end if


        # copy input settings
        self.transfer_from(mach_kw.copy())
        self.transfer_from(gamess_kw.copy())

        # process machine settings
        self.process_machine_settings(mach_kw)

        # process nexus core settings
        self.process_core_settings(kw)

        # process nexus noncore settings
        self.process_noncore_settings(kw)

        # transfer select core data to the global namespace
        nexus_core_noncore.transfer_from(nexus_core,nexus_core_noncore.keys())
        nexus_noncore.set(**nexus_core_noncore.copy()) # prevent write to core namespace

        # copy final core and noncore settings
        self.transfer_from(nexus_core.copy())
        self.transfer_from(nexus_noncore.copy())


        # process gamess settings
        Gamess.settings(**gamess_kw)

        return
Ejemplo n.º 6
0
 def error(self,message,header='settings',exit=True,trace=True):
     NexusCore.error(self,message,header,exit,trace)
Ejemplo n.º 7
0
    def __call__(self, **kwargs):

        NexusCore.write_splash()

        self.log('Applying user settings')

        # guard against invalid settings
        not_allowed = set(kwargs.keys()) - Settings.allowed_vars
        if len(not_allowed) > 0:
            self.error(
                'unrecognized variables provided\nyou provided: {0}\nallowed variables are: {1}'
                .format(sorted(not_allowed), sorted(Settings.allowed_vars)))
        #end if

        # assign simple variables
        for name in Settings.core_assign_vars:
            if name in kwargs:
                nexus_core[name] = kwargs[name]
            #end if
        #end for

        # assign simple variables
        for name in Settings.noncore_assign_vars:
            if name in kwargs:
                nexus_noncore[name] = kwargs[name]
            #end if
        #end for

        # extract settings based on keyword groups
        kw = Settings.kw_set(Settings.nexus_vars, kwargs)
        mach_kw = Settings.kw_set(Settings.machine_vars, kwargs)
        gamess_kw = Settings.kw_set(Settings.gamess_vars, kwargs)
        pwscf_kw = Settings.kw_set(Settings.pwscf_vars, kwargs)
        if len(kwargs) > 0:
            self.error(
                'some settings keywords have not been accounted for\nleftover keywords: {0}\nthis is a developer error'
                .format(sorted(kwargs.keys())))
        #end if

        # copy input settings
        self.transfer_from(mach_kw.copy())
        self.transfer_from(gamess_kw.copy())
        self.transfer_from(pwscf_kw.copy())

        # process machine settings
        self.process_machine_settings(mach_kw)

        # process nexus core settings
        self.process_core_settings(kw)

        # process nexus noncore settings
        self.process_noncore_settings(kw)

        # transfer select core data to the global namespace
        nexus_core_noncore.transfer_from(nexus_core, nexus_core_noncore.keys())
        nexus_noncore.set(
            **nexus_core_noncore.copy())  # prevent write to core namespace

        # copy final core and noncore settings
        self.transfer_from(nexus_core.copy())
        self.transfer_from(nexus_noncore.copy())

        # process gamess settings
        Gamess.settings(**gamess_kw)

        # process pwscf settings
        Pwscf.settings(**pwscf_kw)

        return
Ejemplo n.º 8
0
 def error(self, message, header='settings', exit=True, trace=True):
     NexusCore.error(self, message, header, exit, trace)
Ejemplo n.º 9
0
def test_empty_init():
    from nexus_base import NexusCore
    nc = NexusCore()
Ejemplo n.º 10
0
    def __call__(self, **kwargs):
        kwargs = obj(**kwargs)

        # guard against invalid settings
        not_allowed = set(kwargs.keys()) - Settings.allowed_vars
        if len(not_allowed) > 0:
            self.error(
                'unrecognized variables provided\nyou provided: {0}\nallowed variables are: {1}'
                .format(sorted(not_allowed), sorted(Settings.allowed_vars)))
        #end if

        # restore default core default settings
        restore_nexus_core_defaults()

        # process command line inputs, if any
        if 'command_line' in kwargs:
            nexus_core.command_line = kwargs.command_line
        #end if
        if nexus_core.command_line:
            self.process_command_line_settings(kwargs)
        #end if

        NexusCore.write_splash()

        # print version information
        try:
            from versions import versions
            if versions is not None:
                err, s, serr = versions.check(write=False, full=True)
                self.log(s)
            #end if
        except Exception:
            None
        #end try

        self.log('Applying user settings')

        # assign simple variables
        for name in Settings.core_assign_vars:
            if name in kwargs:
                nexus_core[name] = kwargs[name]
            #end if
        #end for

        # assign simple variables
        for name in Settings.noncore_assign_vars:
            if name in kwargs:
                nexus_noncore[name] = kwargs[name]
            #end if
        #end for

        # extract settings based on keyword groups
        kw = Settings.kw_set(Settings.nexus_vars, kwargs)
        mach_kw = Settings.kw_set(Settings.machine_vars, kwargs)
        gamess_kw = Settings.kw_set(Settings.gamess_vars, kwargs)
        pwscf_kw = Settings.kw_set(Settings.pwscf_vars, kwargs)
        qm_pkg_kw = Settings.kw_set(Settings.qm_package_vars, kwargs)
        if len(kwargs) > 0:
            self.error(
                'some settings keywords have not been accounted for\nleftover keywords: {0}\nthis is a developer error'
                .format(sorted(kwargs.keys())))
        #end if

        # copy input settings
        self.transfer_from(mach_kw.copy())
        self.transfer_from(gamess_kw.copy())
        self.transfer_from(pwscf_kw.copy())

        # process machine settings
        self.process_machine_settings(mach_kw)

        # process nexus core settings
        self.process_core_settings(kw)

        # process nexus noncore settings
        self.process_noncore_settings(kw)

        # transfer select core data to the global namespace
        nexus_core_noncore.transfer_from(nexus_core,
                                         list(nexus_core_noncore.keys()))
        nexus_noncore.set(
            **nexus_core_noncore.copy())  # prevent write to core namespace

        # copy final core and noncore settings
        self.transfer_from(nexus_core.copy())
        self.transfer_from(nexus_noncore.copy())

        # process gamess settings
        Gamess.restore_default_settings()
        Gamess.settings(**gamess_kw)

        # process pwscf settings
        Pwscf.restore_default_settings()
        Pwscf.settings(**pwscf_kw)

        # process quantum package settings
        QuantumPackage.restore_default_settings()
        QuantumPackage.settings(**qm_pkg_kw)

        return