def test_md(factory): # XXX ugly hack ver = factory.factory.version() if tokenize_version(ver) < tokenize_version('3.8'): pytest.skip('No stress tensor until openmx 3.8+') bud = Atoms('CH4', np.array([[0.000000, 0.000000, 0.100000], [0.682793, 0.682793, 0.682793], [-0.682793, -0.682793, 0.68279], [-0.682793, 0.682793, -0.682793], [0.682793, -0.682793, -0.682793]]), cell=[10, 10, 10]) calc = factory.calc( label='ch4', xc='GGA', energy_cutoff=300 * Ry, convergence=1e-4 * Ha, # Use 'C_PBE19' and 'H_PBE19' for version 3.9 definition_of_atomic_species=[['C', 'C5.0-s1p1', 'C_PBE13'], ['H', 'H5.0-s1', 'H_PBE13']], kpts=(1, 1, 1), eigensolver='Band') bud.calc = calc with Trajectory('example.traj', 'w', bud) as traj: ucf = UnitCellFilter(bud, mask=[True, True, False, False, False, False]) dyn = QuasiNewton(ucf) dyn.attach(traj.write) dyn.run(fmax=0.1) bud.get_potential_energy()
def require_version(self, version): from ase.utils import tokenize_version installed_version = self.factory.version() old = tokenize_version(installed_version) < tokenize_version(version) if old: pytest.skip('Version too old: Requires {}; got {}' .format(version, installed_version))
def test_dftb_bandstructure(dftb_factory): # We need to get the DFTB+ version to know # whether to skip this test or not. # For this, we need to run DFTB+ and grep # the version from the output header. # cmd = os.environ['ASE_DFTB_COMMAND'].split()[0] # cmd = dftb_factory.ex version = dftb_factory.version() if tokenize_version(version) < tokenize_version('17.1'): pytest.skip('Band structure requires DFTB 17.1+') calc = dftb_factory.calc(label='dftb', kpts=(3, 3, 3), Hamiltonian_SCC='Yes', Hamiltonian_SCCTolerance=1e-5, Hamiltonian_MaxAngularMomentum_Si='d') atoms = bulk('Si') atoms.calc = calc atoms.get_potential_energy() efermi = calc.get_fermi_level() assert abs(efermi - -2.90086680996455) < 1. # DOS does not currently work because of # missing "get_k_point_weights" function #from ase.dft.dos import DOS #dos = DOS(calc, width=0.2) #d = dos.get_dos() #e = dos.get_energies() #print(d, e) calc = dftb_factory.calc(atoms=atoms, label='dftb', kpts={ 'path': 'WGXWLG', 'npoints': 50 }, Hamiltonian_SCC='Yes', Hamiltonian_MaxSCCIterations=1, Hamiltonian_ReadInitialCharges='Yes', Hamiltonian_MaxAngularMomentum_Si='d') atoms.calc = calc calc.calculate(atoms) #calc.results['fermi_levels'] = [efermi] calc.band_structure()
def read_atoms(backend, header: Tuple = None, traj: TrajectoryReader = None, _try_except: bool = True) -> Atoms: if _try_except: try: return read_atoms(backend, header, traj, False) except Exception as ex: if (traj is not None and tokenize_version(__version__) < tokenize_version(traj.ase_version)): msg = ('You are trying to read a trajectory file written ' f'by ASE-{traj.ase_version} from ASE-{__version__}. ' 'It might help to update your ASE') raise VersionTooOldError(msg) from ex else: raise b = backend if header: pbc, numbers, masses, constraints = header else: pbc = b.pbc numbers = b.numbers masses = b.get('masses') constraints = b.get('constraints', '[]') atoms = Atoms(positions=b.positions, numbers=numbers, cell=b.cell, masses=masses, pbc=pbc, info=b.get('info'), constraint=[dict2constraint(d) for d in decode(constraints)], momenta=b.get('momenta'), magmoms=b.get('magmoms'), charges=b.get('charges'), tags=b.get('tags')) return atoms
def test_tokenize_version_equal(): version = '3.8x.xx' assert tokenize_version(version) == tokenize_version(version)
def test_tokenize_version_lessthan(v1, v2): v1 = tokenize_version(v1) v2 = tokenize_version(v2) assert v1 < v2