コード例 #1
0
 def read(self, label):
     self.parameters = {}
     self.set_label(label)
     if label[-5:] in ['.dat', '.out', '.log']:
         label = label[:-4]
     atoms = read_openmx(filename=label, debug=self.debug)
     self.update_atoms(atoms)
     self.parameters.update(atoms.calc.parameters)
     self.results = atoms.calc.results
     self.parameters['restart'] = self.label
     self.parameters['label'] = label
コード例 #2
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
コード例 #3
0
ファイル: test_openmx.py プロジェクト: maurergroup/ase_local
def test_openmx_out():
    with open('openmx_fio_test.out', 'w') as fd:
        fd.write(openmx_out_sample)
    atoms = read_openmx('openmx_fio_test')
    tol = 1e-2

    # Expected values
    energy = -8.0551
    energies = np.array([-6.2612, -0.4459, -0.4459, -0.4509, -0.4509])
    forces = np.array([[0.00000, 0.00000, -0.091659],
                       [0.02700, 0.02700, 0.029454],
                       [-0.02700, -0.02700, 0.029455],
                       [0.00894, -0.00894, 0.016362],
                       [-0.00894, 0.00894, 0.016362]])

    assert isinstance(atoms, Atoms)

    assert np.isclose(atoms.calc.results['energy'], energy * Ha, atol=tol)
    assert np.all(
        np.isclose(atoms.calc.results['energies'], energies * Ha, atol=tol))
    assert np.all(
        np.isclose(atoms.calc.results['forces'], forces * Ha / Bohr, atol=tol))