def test_siesta_zmat(): import os from ase.calculators.siesta.siesta import Siesta from ase.constraints import FixAtoms, FixedLine, FixedPlane from ase import Atoms pseudo_path = 'pseudos' if not os.path.exists(pseudo_path): os.makedirs(pseudo_path) # Make dummy pseudopotentials. for symbol in 'HCO': with open('{0}/{1}.lda.psf'.format(pseudo_path, symbol), 'w') as fd: fd.close() atoms = Atoms('CO2', [(0.0, 0.0, 0.0), (-1.178, 0.0, 0.0), (1.178, 0.0, 0.0)]) c1 = FixAtoms(indices=[0]) c2 = FixedLine(1, [0.0, 1.0, 0.0]) c3 = FixedPlane(2, [1.0, 0.0, 0.0]) atoms.set_constraint([c1, c2, c3]) custom_dir = './dir1/' # Test simple fdf-argument case. siesta = Siesta(label=custom_dir + 'test_label', symlink_pseudos=False, atomic_coord_format='zmatrix', fdf_arguments={ 'MD.TypeOfRun': 'CG', 'MD.NumCGsteps': 1000 }) atoms.set_calculator(siesta) siesta.write_input(atoms, properties=['energy']) assert os.path.isfile(os.path.join(custom_dir, 'C.lda.1.psf')) assert os.path.isfile(os.path.join(custom_dir, 'O.lda.2.psf')) with open(os.path.join(custom_dir, 'test_label.fdf'), 'r') as fd: lines = fd.readlines() lsl = [line.split() for line in lines] assert ['cartesian'] in lsl assert ['%block', 'Zmatrix'] in lsl assert ['%endblock', 'Zmatrix'] in lsl assert ['MD.TypeOfRun', 'CG'] in lsl assert any( [line.split()[4:9] == ['0', '0', '0', '1', 'C'] for line in lines]) assert any( [line.split()[4:9] == ['0', '1', '0', '2', 'O'] for line in lines]) assert any( [line.split()[4:9] == ['0', '1', '1', '3', 'O'] for line in lines])
c_basis = """2 nodes 1.00 0 1 S 0.20 P 1 0.20 6.00 5.00 1.00 1 2 S 0.20 P 1 E 0.20 6.00 6.00 5.00 1.00 0.95""" species = Species(symbol='C', basis_set=PAOBasisBlock(c_basis)) calc = Siesta( label='ch4', basis_set='SZ', xc='LYP', mesh_cutoff=300 * Ry, species=[species], restart='ch4.XV', fdf_arguments={ 'DM.Tolerance': 1E-5, 'DM.MixingWeight': 0.15, 'DM.NumberPulay': 3, 'MaxSCFIterations': 200, 'ElectronicTemperature': (0.02585, 'eV'), # 300 K 'SaveElectrostaticPotential': True }) bud.calc = calc dyn = QuasiNewton(bud, trajectory=traj) dyn.run(fmax=0.02) e = bud.get_potential_energy()
atoms = Atoms('CO2', [(0.0, 0.0, 0.0), (-1.178, 0.0, 0.0), (1.178, 0.0, 0.0)]) c1 = FixAtoms(indices=[0]) c2 = FixedLine(1, [0.0, 1.0, 0.0]) c3 = FixedPlane(2, [1.0, 0.0, 0.0]) atoms.set_constraint([c1, c2, c3]) custom_dir = './dir1/' # Test simple fdf-argument case. siesta = Siesta(label=custom_dir + 'test_label', symlink_pseudos=False, atomic_coord_format='zmatrix', fdf_arguments={ 'MD.TypeOfRun': 'CG', 'MD.NumCGsteps': 1000 }) atoms.set_calculator(siesta) siesta.write_input(atoms, properties=['energy']) assert os.path.isfile(os.path.join(custom_dir, 'C.lda.1.psf')) assert os.path.isfile(os.path.join(custom_dir, 'O.lda.2.psf')) with open(os.path.join(custom_dir, 'test_label.fdf'), 'r') as fd: lines = fd.readlines() lsl = [line.split() for line in lines] assert ['cartesian'] in lsl assert ['%block', 'Zmatrix'] in lsl
import ase.build from ase.calculators.siesta.siesta import Siesta # Test real calculation of the lithium bulk which produced a gapped .EIG file atoms = ase.build.bulk('Li', cubic=True) calc = Siesta(kpts=[2,1,1]) atoms.set_calculator(calc) atoms.get_potential_energy() assert calc.results['eigenvalues'].shape[:2] == (1, 2) # spins x bands assert calc.get_k_point_weights().shape == (2,) assert calc.get_ibz_k_points().shape == (2, 3)
from ase.calculators.calculator import FileIOCalculator from ase import Atoms from ase.utils import basestring # Setup test structures. h = Atoms('H', [(0.0, 0.0, 0.0)]) co2 = Atoms('CO2', [(0.0, 0.0, 0.0), (-1.178, 0.0, 0.0), (1.178, 0.0, 0.0)]) ch4 = Atoms('CH4', np.array([ [0.000000, 0.000000, 0.000000], [0.682793, 0.682793, 0.682793], [-0.682793, -0.682793, 0.682790], [-0.682793, 0.682793, -0.682793], [0.682793, -0.682793, -0.682793]])) # Test the initialization. siesta = Siesta() assert isinstance(siesta, FileIOCalculator) assert isinstance(siesta.implemented_properties, tuple) assert isinstance(siesta.default_parameters, dict) assert isinstance(siesta.name, basestring) assert isinstance(siesta.default_parameters, dict) # Test simple fdf-argument case. atoms = h.copy() siesta = Siesta( label='test_label', fdf_arguments={'DM.Tolerance': 1e-3}) atoms.set_calculator(siesta) siesta.write_input(atoms, properties=['energy']) atoms = h.copy() atoms.set_calculator(siesta)
def test_siesta(): import numpy as np from ase.calculators.siesta.siesta import Siesta from ase.calculators.siesta.parameters import Species, PAOBasisBlock from ase.calculators.calculator import FileIOCalculator from ase import Atoms # Setup test structures. h = Atoms('H', [(0.0, 0.0, 0.0)]) ch4 = Atoms('CH4', np.array([ [0.000000, 0.000000, 0.000000], [0.682793, 0.682793, 0.682793], [-0.682793, -0.682793, 0.682790], [-0.682793, 0.682793, -0.682793], [0.682793, -0.682793, -0.682793]])) # Test the initialization. siesta = Siesta() assert isinstance(siesta, FileIOCalculator) assert isinstance(siesta.implemented_properties, tuple) assert isinstance(siesta.default_parameters, dict) assert isinstance(siesta.name, str) assert isinstance(siesta.default_parameters, dict) # Test simple fdf-argument case. atoms = h.copy() siesta = Siesta( label='test_label', fdf_arguments={'DM.Tolerance': 1e-3}) atoms.set_calculator(siesta) siesta.write_input(atoms, properties=['energy']) atoms = h.copy() atoms.set_calculator(siesta) siesta.write_input(atoms, properties=['energy']) with open('test_label.fdf', 'r') as fd: lines = fd.readlines() assert any([line.split() == ['DM.Tolerance', '0.001'] for line in lines]) # Test (slightly) more complex case of setting fdf-arguments. siesta = Siesta( label='test_label', mesh_cutoff=3000, fdf_arguments={ 'DM.Tolerance': 1e-3, 'ON.eta': (5, 'Ry')}) atoms.set_calculator(siesta) siesta.write_input(atoms, properties=['energy']) atoms = h.copy() atoms.set_calculator(siesta) siesta.write_input(atoms, properties=['energy']) with open('test_label.fdf', 'r') as f: lines = f.readlines() assert 'MeshCutoff\t3000\teV\n' in lines assert 'DM.Tolerance\t0.001\n' in lines assert 'ON.eta\t5\tRy\n' in lines # Test setting fdf-arguments after initiation. siesta.set_fdf_arguments( {'DM.Tolerance': 1e-2, 'ON.eta': (2, 'Ry')}) siesta.write_input(atoms, properties=['energy']) with open('test_label.fdf', 'r') as f: lines = f.readlines() assert 'MeshCutoff\t3000\teV\n' in lines assert 'DM.Tolerance\t0.01\n' in lines assert 'ON.eta\t2\tRy\n' in lines # Test initiation using Species. atoms = ch4.copy() species, numbers = siesta.species(atoms) assert all(numbers == np.array([1, 2, 2, 2, 2])) siesta = Siesta(species=[Species(symbol='C', tag=1)]) species, numbers = siesta.species(atoms) assert all(numbers == np.array([1, 2, 2, 2, 2])) atoms.set_tags([0, 0, 0, 1, 0]) species, numbers = siesta.species(atoms) assert all(numbers == np.array([1, 2, 2, 2, 2])) siesta = Siesta(species=[Species(symbol='H', tag=1, basis_set='SZ')]) species, numbers = siesta.species(atoms) assert all(numbers == np.array([1, 2, 2, 3, 2])) siesta = Siesta(label='test_label', species=species) siesta.write_input(atoms, properties=['energy']) with open('test_label.fdf', 'r') as f: lines = f.readlines() lines = [line.split() for line in lines] assert ['1', '6', 'C.lda.1'] in lines assert ['2', '1', 'H.lda.2'] in lines assert ['3', '1', 'H.lda.3'] in lines assert ['C.lda.1', 'DZP'] in lines assert ['H.lda.2', 'DZP'] in lines assert ['H.lda.3', 'SZ'] in lines # Test if PAO block can be given as species. c_basis = """2 nodes 1.00 0 1 S 0.20 P 1 0.20 6.00 5.00 1.00 1 2 S 0.20 P 1 E 0.20 6.00 6.00 5.00 1.00 0.95""" basis_set = PAOBasisBlock(c_basis) species = Species(symbol='C', basis_set=basis_set) siesta = Siesta(label='test_label', species=[species]) siesta.write_input(atoms, properties=['energy']) with open('test_label.fdf', 'r') as f: lines = f.readlines() lines = [line.split() for line in lines] assert ['%block', 'PAO.Basis'] in lines assert ['%endblock', 'PAO.Basis'] in lines
# Setup test structures. h = Atoms('H', [(0.0, 0.0, 0.0)]) co2 = Atoms('CO2', [(0.0, 0.0, 0.0), (-1.178, 0.0, 0.0), (1.178, 0.0, 0.0)]) ch4 = Atoms('CH4', np.array([ [0.000000, 0.000000, 0.000000], [0.682793, 0.682793, 0.682793], [-0.682793, -0.682793, 0.682790], [-0.682793, 0.682793, -0.682793], [0.682793, -0.682793, -0.682793]])) # Setup required environment variables. os.environ['SIESTA_PP_PATH'] = '../' + pseudo_path # Test the initialization. siesta = Siesta() assert isinstance(siesta, FileIOCalculator) assert isinstance(siesta.implemented_properties, tuple) assert isinstance(siesta.default_parameters, dict) assert isinstance(siesta.name, str) assert isinstance(siesta.default_parameters, dict) # Test simple fdf-argument case. atoms = h.copy() siesta = Siesta( label='test_label', fdf_arguments={'DM.Tolerance': 1e-3}) atoms.set_calculator(siesta) siesta.write_input(atoms, properties=['energy']) atoms = h.copy() atoms.set_calculator(siesta)
# Change to test directory. os.chdir(run_path) atoms = Atoms('CO2', [(0.0, 0.0, 0.0), (-1.178, 0.0, 0.0), (1.178, 0.0, 0.0)]) c1 = FixAtoms(indices=[0]) c2 = FixedLine(1, [0.0, 1.0, 0.0]) c3 = FixedPlane(2, [1.0, 0.0, 0.0]) atoms.set_constraint([c1, c2, c3]) # Test simple fdf-argument case. siesta = Siesta(label='test_label', atomic_coord_format='zmatrix', fdf_arguments={ 'MD.TypeOfRun': 'CG', 'MD.NumCGsteps': 1000 }) atoms.set_calculator(siesta) custom_dir = './dir1/' siesta.set_directory(custom_dir) siesta.write_input(atoms, properties=['energy']) assert os.path.isfile(os.path.join(custom_dir, 'C.lda.1.psf')) assert os.path.isfile(os.path.join(custom_dir, 'O.lda.2.psf')) with open(os.path.join(custom_dir, 'test_label.fdf'), 'r') as fd: lines = fd.readlines() lsl = [line.split() for line in lines]
def __init__(self, *args, **kwargs): warnings.warn( "The BaseSiesta calculator class will no longer be supported. " "Use 'ase.calculators.siesta.Siesta in stead.", np.VisibleDeprecationWarning) Siesta.__init__(self, *args, **kwargs)
os.system('touch %s/O.lda.psf' % pseudo_path) h = Atoms('H', [(0.0, 0.0, 0.0)]) co2 = Atoms('CO2', [(0.0, 0.0, 0.0), (-1.178, 0.0, 0.0), (1.178, 0.0, 0.0)]) ch4 = Atoms( 'CH4', np.array([[0.000000, 0.000000, 0.000000], [0.682793, 0.682793, 0.682793], [-0.682793, -0.682793, 0.682790], [-0.682793, 0.682793, -0.682793], [0.682793, -0.682793, -0.682793]])) os.chdir(run_path) os.environ['SIESTA_PP_PATH'] = '../' + pseudo_path # Test the initialization siesta = Siesta() assert isinstance(siesta, FileIOCalculator) assert isinstance(siesta.implemented_properties, tuple) assert isinstance(siesta.default_parameters, dict) assert isinstance(siesta.name, str) assert isinstance(siesta.default_parameters, dict) # Test the more complicated species situations atoms = ch4.copy() species, numbers = siesta.species(atoms) assert all(numbers == np.array([1, 2, 2, 2, 2])) siesta = Siesta(species=[Specie(symbol='C', tag=1)]) species, numbers = siesta.species(atoms) assert all(numbers == np.array([1, 2, 2, 2, 2])) atoms.set_tags([0, 0, 0, 1, 0]) species, numbers = siesta.species(atoms)