コード例 #1
0
    def clean(self, prefix='test', queue_num=None):
        """Method which cleans up after a calculation.

        The default files generated OpenMX will be deleted IF this
        method is called.

        """
        self.prind("Cleaning Data")
        fileName = get_file_name('', self.label)
        pbs_Name = get_file_name('', self.label)
        files = [
            # prefix+'.out',#prefix+'.dat',#prefix+'.BAND*',
            fileName + '.cif', fileName + '.dden.cube', fileName + \
            '.ene', fileName + '.md', fileName + '.md2',
            fileName + '.tden.cube', fileName + '.sden.cube', fileName + \
            '.v0.cube', fileName + '.v1.cube',
            fileName + '.vhart.cube', fileName + '.den0.cube', fileName + \
            '.bulk.xyz', fileName + '.den1.cube',
            fileName + '.xyz', pbs_Name + '.o' + \
            str(queue_num), pbs_Name + '.e' + str(queue_num)
        ]
        for f in files:
            try:
                self.prind("Removing" + f)
                os.remove(f)
            except OSError:
                self.prind("There is no such file named " + f)
コード例 #2
0
def write_openmx(label=None, atoms=None, parameters=None, properties=None,
                 system_changes=None):
    """
    From atom image, 'images', write '.dat' file.
    First, set
    Write input (dat)-file.
    See calculator.py for further details.

    Parameters:
        - atoms        : The Atoms object to write.
        - properties   : The properties which should be calculated.
        - system_changes : List of properties changed since last run.
    """
    from ase.calculators.openmx import parameters as param
    filtered_keywords = parameters_to_keywords(label=label, atoms=atoms,
                                               parameters=parameters,
                                               properties=properties,
                                               system_changes=system_changes)
    keys = ['string', 'bool', 'integer', 'float',
            'tuple_integer', 'tuple_float', 'tuple_bool',
            'matrix', 'list_int', 'list_bool', 'list_float']
    # Start writing the file
    filename = get_file_name('.dat', label)
    with open(filename, 'w') as f:
        # Write 1-line keywords
        for fltrd_keyword in filtered_keywords.keys():
            for key in keys:
                openmx_keywords = getattr(param, key+'_keys')
                write = globals()['write_'+key]
                for omx_keyword in openmx_keywords:
                    if fltrd_keyword == get_standard_key(omx_keyword):
                        write(f, omx_keyword, filtered_keywords[fltrd_keyword])
コード例 #3
0
 def read_version(self, label=None):
     version = None
     if label is None:
         label = self.label
     for line in open(get_file_name('.out', label)):
         if line.find('Ver.') != -1:
             version = line.split()[-1]
             break
     return version
コード例 #4
0
 def run_openmx(self):
     def isRunning(process=None):
         ''' Check mpi is running'''
         return process.poll() is None
     runfile = get_file_name('.dat', self.label, absolute_directory=False)
     outfile = get_file_name('.log', self.label)
     olddir = os.getcwd()
     abs_dir = os.path.join(olddir, self.directory)
     try:
         os.chdir(abs_dir)
         if self.command is None:
             self.command = 'openmx'
         command = self.command + ' %s > %s'
         command = command % (runfile, outfile)
         self.prind(command)
         p = subprocess.Popen(command, shell=True, universal_newlines=True)
         self.print_file(file=outfile, running=isRunning, process=p)
     finally:
         os.chdir(olddir)
     self.prind("Calculation Finished")
コード例 #5
0
 def run_mpi(self):
     """
     Run openmx using MPI method. If keyword `mpi` is declared, it will
     run.
     """
     def isRunning(process=None):
         ''' Check mpi is running'''
         return process.poll() is None
     processes = self.processes
     threads = self.threads
     runfile = get_file_name('.dat', self.label, absolute_directory=False)
     outfile = get_file_name('.log', self.label)
     olddir = os.getcwd()
     abs_dir = os.path.join(olddir, self.directory)
     try:
         os.chdir(abs_dir)
         command = self.get_command(processes, threads, runfile, outfile)
         self.prind(command)
         p = subprocess.Popen(command, shell=True, universal_newlines=True)
         self.print_file(file=outfile, running=isRunning, process=p)
     finally:
         os.chdir(olddir)
     self.prind("Calculation Finished")
コード例 #6
0
    def calculate(self,
                  atoms=None,
                  properties=None,
                  system_changes=all_changes):
        """
        Capture the RuntimeError from FileIOCalculator.calculate
        and  add a little debug information from the OpenMX output.
        See base FileIOCalculator for documentation.
        """
        if self.parameters.data_path is None:
            if not 'OPENMX_DFT_DATA_PATH' in os.environ:
                warnings.warn('Please either set OPENMX_DFT_DATA_PATH as an'
                              'enviroment variable or specify dft_data_path as'
                              'a keyword argument')

        self.prind("Start Calculation")
        if properties is None:
            properties = self.implemented_properties
        try:
            Calculator.calculate(self, atoms, properties, system_changes)
            self.write_input(atoms=self.atoms,
                             parameters=self.parameters,
                             properties=properties,
                             system_changes=system_changes)
            self.print_input(debug=self.debug, nohup=self.nohup)
            self.run()
            #  self.read_results()
            self.version = self.read_version()
            output_atoms = read_openmx(filename=self.label, debug=self.debug)
            self.output_atoms = output_atoms
            # XXX The parameters are supposedly inputs, so it is dangerous
            # to update them from the outputs. --askhl
            self.parameters.update(output_atoms.calc.parameters)
            self.results = output_atoms.calc.results
            # self.clean()
        except RuntimeError as e:
            try:
                with open(get_file_name('.log'), 'r') as f:
                    lines = f.readlines()
                debug_lines = 10
                print('##### %d last lines of the OpenMX output' % debug_lines)
                for line in lines[-20:]:
                    print(line.strip())
                print('##### end of openMX output')
                raise e
            except RuntimeError as e:
                raise e
コード例 #7
0
 def print_input(self, debug=None, nohup=None):
     """
     For a debugging purpose, print the .dat file
     """
     if debug is None:
         debug = self.debug
     if nohup is None:
         nohup = self.nohup
     self.prind('Reading input file' + self.label)
     filename = get_file_name('.dat', self.label)
     if not nohup:
         with open(filename, 'r') as f:
             while True:
                 line = f.readline()
                 print(line.strip())
                 if not line:
                     break