def test_abinit_cmdline(): from ase.test import cli cli( """ ase build -x fcc -a 4.04 Al | ase -T run abinit -p xc=PBE,kpts=3.0,ecut=340,toldfe=1e-5,chksymbreak=0""", 'abinit')
def test_elk_cmdline(): from ase.test import cli, require # warning! parameters are not converged - only an illustration! require('elk') cli("""ase build -x fcc -a 4.04 Al | \ ase run elk -p \ "tasks=0,kpts=1.5,rgkmax=5.0,tforce=True,smearing=(fermi-dirac,0.05)" """)
def test_aims_cmdline(): from ase.test import cli, require require('aims') # warning! parameters are not converged - only an illustration! cli("""ase build -x bcc -a 3.6 Li | \ ase run aims -s 0.3 -p \ kpts=1.5,xc=LDA,sc_accuracy_rho=5.e-2,relativistic=none,compute_analytical_stress=True,sc_accuracy_forces=5.e-1""" )
def test_ag(): from ase import Atoms from ase.io import write from ase.test import cli write('x.json', Atoms('X')) # Make sure ASE's gui can run in terminal mode without $DISPLAY and tkinter: cli('ase -T gui --terminal -n "id=1" x.json')
def test_cmdline(): require('nwchem') cli("""\ ase build O O.traj && ase run nwchem O.traj -o nwchem_cmdline.json && ase build O2 O2.traj && ase run nwchem O2.traj -o nwchem_cmdline.json""") c = connect('nwchem_cmdline.json') dct = read_json('nwchem_cmdline.json') for name in ['O2', 'O']: d = c.get([('formula', '=', name)]) id = d.id e1 = d.energy e2 = c.get_atoms(id).get_potential_energy() e3 = read('{name}.nwo'.format(name=name)).get_potential_energy() e4 = dct[id]['energy'] assert e1 == e2 == e3 == e4 print(e1) ae = 2 * c.get('formula=O').energy - c.get('formula=O2').energy assert_allclose(ae, 6.599194233179787, atol=1e-4, rtol=1e-4)
def test_gaussian_cmdline(): from ase.test import cli, require from ase.db import connect from ase.io import read from ase.io.jsonio import read_json require('gaussian') cli("""\ ase build O O.xyz && ase run gaussian O.xyz -o gaussian_cmdline.json && ase build O2 O2.xyz && ase run gaussian O2.xyz -o gaussian_cmdline.json""") c = connect('gaussian_cmdline.json') dct = read_json('gaussian_cmdline.json') for index, name in enumerate(['O', 'O2']): d = c.get(index + 1) id = d.id e1 = d.energy e2 = c.get_atoms(id).get_potential_energy() e3 = read(name + '.log').get_potential_energy() e4 = dct[id]['energy'] assert e1 == e2 == e3 == e4 print(e1) ae = 2 * c.get(1).energy - c.get(2).energy assert abs(ae - 0.65376) < 1e-3
from ase.test import cli, require from ase.db import connect from ase.io.jsonio import read_json from ase.calculators.nwchem import NWChem require('nwchem') cli("""\ ase build O O.traj && ase run nwchem O.traj -o nwchem_cmdline.json && ase build O2 O2.traj && ase run nwchem O2.traj -o nwchem_cmdline.json""") c = connect('nwchem_cmdline.json') dct = read_json('nwchem_cmdline.json') for name in ['O2', 'O']: d = c.get([('formula', '=', name)]) id = d.id e1 = d.energy e2 = c.get_atoms(id).get_potential_energy() e3 = NWChem.read_atoms(name).get_potential_energy() e4 = dct[id]['energy'] assert e1 == e2 == e3 == e4 print(e1) ae = 2 * c.get('formula=O').energy - c.get('formula=O2').energy assert abs(ae - 6.6053) < 1e-4
from ase.test import cli, require require('aims') # warning! parameters are not converged - only an illustration! cli("""ase-build -x bcc -a 3.6 Li | \ ase-run aims -s 0.3 -p \ kpts=1.5,xc=LDA,sc_accuracy_rho=5.e-2,relativistic=none,compute_analytical_stress=True,sc_accuracy_forces=5.e-1""")
from ase.test import cli, require from ase.db import connect from ase.io.jsonio import read_json from ase.calculators.nwchem import NWChem require('nwchem') cli("""ase build O | ase run nwchem -d nwchem_cmdline.json && ase build O2 | ase run nwchem -d nwchem_cmdline.json""") c = connect('nwchem_cmdline.json') dct = read_json('nwchem_cmdline.json') for name in ['O2', 'O']: d = c.get([('name', '=', name)]) id = d.id e1 = d.energy e2 = c.get_atoms(id).get_potential_energy() e3 = NWChem.read_atoms(name).get_potential_energy() e4 = dct[id]['energy'] assert e1 == e2 == e3 == e4 print(e1) ae = 2 * c.get('name=O').energy - c.get('name=O2').energy assert abs(ae - 6.6053) < 1e-4
from ase.test import cli, require # warning! parameters are not converged - only an illustration! require('elk') cli("""ase build -x fcc -a 4.04 Al | \ ase run elk -p \ "tasks=0,kpts=1.5,rgkmax=5.0,tforce=True,smearing=(fermi-dirac,0.05)" """)
from ase.test import cli, require from ase.db import connect from ase.db.jsondb import read_json from ase.calculators.nwchem import NWChem require('nwchem') cli("""ase-build O | ase-run nwchem -d nwchem_cmdline.json && ase-build O2 | ase-run nwchem -d nwchem_cmdline.json""") c = connect('nwchem_cmdline.json') dct = read_json('nwchem_cmdline.json') for name in ['O2', 'O']: d = c.get([('name', '=', name)]) id = d.id e1 = d.energy e2 = c.get_atoms(id).get_potential_energy() e3 = NWChem.read_atoms(name).get_potential_energy() e4 = dct[id]['energy'] assert e1 == e2 == e3 == e4 print(e1) ae = 2 * c.get('name=O').energy - c.get('name=O2').energy assert abs(ae - 6.6053) < 1e-4
from ase.test import cli, require require('aims') # warning! parameters are not converged - only an illustration! cli("""ase-build -x bcc -a 3.6 Li | \ ase-run aims -s 0.3 -p \ kpts=1.5,xc=LDA,sc_accuracy_rho=5.e-2,relativistic=none,compute_analytical_stress=True,sc_accuracy_forces=5.e-1""" )
def test_fleur_cmdline(): from ase.test import cli, require require('fleur') cli('ase build -x fcc -a 4.04 Al | ase run fleur -p kpts=3.0,xc=PBE')
import sys from ase import Atoms from ase.io import write from ase.test import cli write('x.json', Atoms('X')) # Make sure ASE's gui can run in terminal mode without $DISPLAY and tkinter: cli('ase -T gui --terminal x.json@id=1') assert 'tkinter' not in sys.modules assert 'Tkinter' not in sys.modules # legacy Python
def test_db(name): def count(n, *args, **kwargs): m = len(list(con.select(columns=['id'], *args, **kwargs))) assert m == n, (m, n) if name == 'postgresql': pytest.importorskip('psycopg2') if os.environ.get('POSTGRES_DB'): # gitlab-ci name = 'postgresql://*****:*****@postgres:5432/testase' else: name = os.environ.get('ASE_TEST_POSTGRES_URL') if name is None: return elif name == 'mysql': pytest.importorskip('pymysql') if os.environ.get('CI_PROJECT_DIR'): # gitlab-ci name = 'mysql://*****:*****@mysql:3306/testase_mysql' else: name = os.environ.get('MYSQL_DB_URL') if name is None: return elif name == 'mariadb': pytest.importorskip('pymysql') if os.environ.get('CI_PROJECT_DIR'): # gitlab-ci name = 'mariadb://*****:*****@mariadb:3306/testase_mysql' else: name = os.environ.get('MYSQL_DB_URL') if name is None: return con = connect(name) if 'postgres' in name or 'mysql' in name or 'mariadb' in name: con.delete([row.id for row in con.select()]) cli(cmd.replace('testase.json', name)) assert con.get_atoms(H=1)[0].magmom == 1 count(5) count(3, 'hydro') count(0, 'foo') count(3, abc=42) count(3, 'abc') count(0, 'abc,foo') count(3, 'abc,hydro') count(0, foo='bar') count(1, formula='H2') count(1, formula='H2O') count(3, 'fmax<0.1') count(1, '0.5<mass<1.5') count(5, 'energy') id = con.reserve(abc=7) assert con[id].abc == 7 for key in ['calculator', 'energy', 'abc', 'name', 'fmax']: count(6, sort=key) count(6, sort='-' + key) cli('ase -T gui --terminal -n 3 {}'.format(name)) con.delete([id])
from ase.test import cli, require require('fleur') cli('ase build -x fcc -a 4.04 Al | ase run fleur -p kpts=3.0,xc=PBE')
from ase.test import cli, require from ase.db import connect require('gaussian') cli("""\ ase-build O | ase-run gaussian -d oxygen.json && ase-build O2 | ase-run gaussian -d oxygen.json""") conn = connect('oxygen.json') e1 = conn['O'].get_potential_energy() e2 = conn['O2'].get_potential_energy() ae = 2 * e1 - e2 print(ae) assert abs(ae - 5.664) < 1e-3
from ase.test import cli from ase.db import connect cmd = """ ase-build H | ase-run emt -d y.json && ase-build H2O | ase-run emt -d y.json && ase-build O2 | ase-run emt -d y.json && ase-build H2 | ase-run emt -f 0.02 -d y.json && ase-build O2 | ase-run emt -f 0.02 -d y.json && ase-build -x fcc Cu | ase-run emt -E 5 -d y.json && ase-db y.json natoms=1,H=1 --delete --yes && ase-db y.json "H>0" -k hydro""" for name in ['y.json', 'y.db']: #, 'postgres://localhost']: cli(cmd.replace('y.json', name)) con = connect(name) assert len(list(con.select())) == 5 assert len(list(con.select('hydro'))) == 2
import sys from ase import Atoms from ase.io import write from ase.test import cli write('x.json', Atoms('X')) # Make sure ASE's gui can run in terminal mode without $DISPLAY and tkinter: cli('ase gui --terminal x.json@id=1') assert 'tkinter' not in sys.modules assert 'Tkinter' not in sys.modules # legacy Python
from ase.test import cli, require from ase.db import connect from ase.io.jsonio import read_json from ase.calculators.gaussian import Gaussian require('gaussian') cli("""\ ase-build O | ase-run gaussian -d gaussian_cmdline.json && ase-build O2 | ase-run gaussian -d gaussian_cmdline.json""") c = connect('gaussian_cmdline.json') dct = read_json('gaussian_cmdline.json') for name in ['O2', 'O']: d = c.get([('name', '=', name)]) id = d.id e1 = d.energy e2 = c.get_atoms(id).get_potential_energy() e3 = Gaussian.read_atoms(name).get_potential_energy() e4 = dct[id]['energy'] assert e1 == e2 == e3 == e4 print(e1) ae = 2 * c.get('name=O').energy - c.get('name=O2').energy assert abs(ae - 1.060) < 1e-3
from ase.test import cli cli(""" ase build -x fcc -a 4.04 Al | ase run abinit -p xc=PBE,kpts=3.0,ecut=340,toldfe=1e-5,chksymbreak=0""", 'abinit')
from ase.test import cli cli( """ ase-build -x fcc -a 4.04 Al | ase-run abinit -p xc=PBE,kpts=3.0,ecut=340,toldfe=1e-5,chksymbreak=0""", 'abinit')
ase build O2 | ase run emt -d y.json && ase build H2 | ase run emt -f 0.02 -d y.json && ase build O2 | ase run emt -f 0.02 -d y.json && ase build -x fcc Cu | ase run emt -E 5,1 -d y.json && ase db -v y.json natoms=1,Cu=1 --delete --yes && ase db -v y.json "H>0" -k hydro=1,abc=42,foo=bar && ase db -v y.json "H>0" --delete-keys foo""" def count(n, *args, **kwargs): m = len(list(con.select(*args, **kwargs))) assert m == n, (m, n) for name in ['y.json', 'y.db']: cli(cmd.replace('y.json', name)) con = connect(name) assert con.get_atoms(H=1)[0].magmom == 1 count(5) count(3, 'hydro') count(0, 'foo') count(3, abc=42) count(3, 'abc') count(0, 'abc,foo') count(3, 'abc,hydro') count(0, foo='bar') count(1, formula='H2') count(1, formula='H2O') count(3, 'fmax<0.1') count(1, '0.5<mass<1.5') count(5, 'energy')
t0 = time.time() for name in ['testase.json', 'testase.db', 'postgresql']: if name == 'postgresql': if os.environ.get('POSTGRES_DB'): # gitlab-ci name = 'postgresql://*****:*****@postgres:5432/testase' else: name = os.environ.get('ASE_TEST_POSTGRES_URL') if name is None: continue con = connect(name) t1 = time.time() if 'postgres' in name: con.delete([row.id for row in con.select()]) cli(cmd.replace('testase.json', name)) assert con.get_atoms(H=1)[0].magmom == 1 count(5) count(3, 'hydro') count(0, 'foo') count(3, abc=42) count(3, 'abc') count(0, 'abc,foo') count(3, 'abc,hydro') count(0, foo='bar') count(1, formula='H2') count(1, formula='H2O') count(3, 'fmax<0.1') count(1, '0.5<mass<1.5') count(5, 'energy')
from ase.test import cli, require from ase.db import connect from ase.db.json import read_json from ase.calculators.nwchem import NWChem require('nwchem') cli("""ase-build O | ase-run nwchem -d oxygen.json && ase-build O2 | ase-run nwchem -d oxygen.json""") conn = connect('oxygen.json') dct = read_json('oxygen.json') for name in ['O2', 'O']: e1 = conn[name].get_potential_energy() e2 = NWChem.read_atoms(name).get_potential_energy() e3 = dct[name]['results']['energy'] assert e1 == e2 == e3 print(e1) ae = 2 * dct['O']['results']['energy'] - dct['O2']['results']['energy'] assert abs(ae - 6.6053) < 1e-4