def check_nrg(value): """ Check for PDF energy against known value :param value: :return: """ # setup atoms1, atoms2 = value[0] exp_dict = value[1] p, thresh = value[2] proc1, alg1 = value[3] scat = ElasticScatter(verbose=True) scat.update_experiment(exp_dict) scat.set_processor(proc1, alg1) if value[4] == 'FQ': exp_func = scat.get_fq exp_grad = scat.get_grad_fq elif value[4] == 'PDF': exp_func = scat.get_pdf exp_grad = scat.get_grad_pdf else: exp_func = None exp_grad = None target_data = exp_func(atoms1) calc = Calc1D(target_data=target_data, exp_function=exp_func, exp_grad_function=exp_grad, potential=p) atoms2.set_calculator(calc) ans = atoms2.get_potential_energy() assert ans >= thresh del atoms1, atoms2, proc1, alg1, p, thresh, scat, target_data, calc, ans
def check_nrg(value): """ Check for PDF energy against known value :param value: :return: """ # setup atoms1, atoms2 = value[0] exp_dict = value[1] p, thresh = value[2] proc1, alg1 = value[3] scat = ElasticScatter(verbose=True) scat.update_experiment(exp_dict) scat.set_processor(proc1, alg1) if value[4] == 'FQ': exp_func = scat.get_fq exp_grad = scat.get_grad_fq elif value[4] == 'PDF': exp_func = scat.get_pdf exp_grad = scat.get_grad_pdf else: exp_func = None exp_grad = None target_data = exp_func(atoms1) calc = Calc1D(target_data=target_data, exp_function=exp_func, exp_grad_function=exp_grad, potential=p) atoms2.set_calculator(calc) ans = atoms2.get_potential_energy() assert ans >= thresh del atoms1, atoms2, proc1, alg1, p, thresh, scat, target_data, calc, ans
def check_nrg(value): """ Check two processor, algorithm pairs against each other for PDF energy Parameters ---------- value: list or tuple The values to use in the tests """ rtol = 4e-6 atol = 9e-6 # setup atoms1, atoms2 = value[0] exp_dict = value[1] p, thresh = value[2] proc1, alg1 = value[3][0] proc2, alg2 = value[3][1] scat = ElasticScatter(verbose=True) scat.update_experiment(exp_dict) scat.set_processor(proc1, alg1) if value[4] == 'FQ': exp_func = scat.get_fq exp_grad = scat.get_grad_fq elif value[4] == 'PDF': exp_func = scat.get_pdf exp_grad = scat.get_grad_pdf else: exp_func = None exp_grad = None target_data = exp_func(atoms1) calc = Calc1D(target_data=target_data, exp_function=exp_func, exp_grad_function=exp_grad, potential=p) atoms2.set_calculator(calc) ans1 = atoms2.get_potential_energy() scat.set_processor(proc2, alg2) calc = Calc1D(target_data=target_data, exp_function=exp_func, exp_grad_function=exp_grad, potential=p) atoms2.set_calculator(calc) ans2 = atoms2.get_potential_energy() stats_check(ans2, ans1, rtol, atol)
def check_forces(value): """ Check two processor, algorithm pairs against each other for PDF forces :param value: :return: """ # setup rtol = 1e-4 atol = 6e-5 atoms1, atoms2 = value[0] exp_dict = value[1] p, thresh = value[2] proc1, alg1 = value[3][0] proc2, alg2 = value[3][1] scat = ElasticScatter(verbose=True) scat.update_experiment(exp_dict) scat.set_processor(proc1, alg1) if value[4] == 'FQ': exp_func = scat.get_fq exp_grad = scat.get_grad_fq elif value[4] == 'PDF': exp_func = scat.get_pdf exp_grad = scat.get_grad_pdf else: exp_func = None exp_grad = None target_data = exp_func(atoms1) calc = Calc1D(target_data=target_data, exp_function=exp_func, exp_grad_function=exp_grad, potential=p) atoms2.set_calculator(calc) ans1 = atoms2.get_forces() scat.set_processor(proc2, alg2) calc = Calc1D(target_data=target_data, exp_function=exp_func, exp_grad_function=exp_grad, potential=p) atoms2.set_calculator(calc) ans2 = atoms2.get_forces() stats_check(ans2, ans1, rtol=rtol, atol=atol)
def check_forces(value): """ Check for PDF forces against known value :param value: :return: """ # setup atoms1, atoms2 = value[0] exp_dict = value[1] p, thresh = value[2] proc1, alg1 = value[3] scat = ElasticScatter(verbose=True) scat.update_experiment(exp_dict) scat.set_processor(proc1, alg1) if value[4] == 'FQ': exp_func = scat.get_fq exp_grad = scat.get_grad_fq elif value[4] == 'PDF': exp_func = scat.get_pdf exp_grad = scat.get_grad_pdf else: exp_func = None exp_grad = None target_data = exp_func(atoms1) calc = Calc1D(target_data=target_data, exp_function=exp_func, exp_grad_function=exp_grad, potential=p) atoms2.set_calculator(calc) # print atoms2.get_potential_energy() forces = atoms2.get_forces() print(forces) com = atoms2.get_center_of_mass() for i in range(len(atoms2)): dist = atoms2[i].position - com stats_check(np.cross(dist, forces[i]), np.zeros(3), atol=1e-7) del dist del atoms1, atoms2, proc1, alg1, p, thresh, scat, target_data, calc, \ forces, com
def check_forces(value): """ Check for PDF forces against known value :param value: :return: """ # setup atoms1, atoms2 = value[0] exp_dict = value[1] p, thresh = value[2] proc1, alg1 = value[3] scat = ElasticScatter(verbose=True) scat.update_experiment(exp_dict) scat.set_processor(proc1, alg1) if value[4] == 'FQ': exp_func = scat.get_fq exp_grad = scat.get_grad_fq elif value[4] == 'PDF': exp_func = scat.get_pdf exp_grad = scat.get_grad_pdf else: exp_func = None exp_grad = None target_data = exp_func(atoms1) calc = Calc1D(target_data=target_data, exp_function=exp_func, exp_grad_function=exp_grad, potential=p) atoms2.set_calculator(calc) # print atoms2.get_potential_energy() forces = atoms2.get_forces() print(forces) com = atoms2.get_center_of_mass() for i in range(len(atoms2)): dist = atoms2[i].position - com stats_check(np.cross(dist, forces[i]), np.zeros(3), atol=1e-7) del dist del atoms1, atoms2, proc1, alg1, p, thresh, scat, target_data, calc, \ forces, com
import numpy as np from ase.atoms import Atoms from pyiid.experiments.elasticscatter import ElasticScatter import matplotlib.pyplot as plt from matplotlib.colors import LogNorm import ase.io __author__ = 'christopher' # atoms = Atoms('Au4', [[0, 0, 0], [3, 0, 0], [0, 3, 0], [3, 3, 0]]) atoms = ase.io.read('/mnt/work-data/dev/IID_data/db_test/PDF_LAMMPS_587.traj') scat = ElasticScatter() scat.update_experiment({'qmax': 8, 'qmin': .5}) s = scat.get_scatter_vector() k = 100 i_max, j_max = k, k pixel_array = np.zeros((i_max, j_max)) for i in range(i_max): for j in range(j_max): pixel_array[i, j] = np.sqrt(i**2 + j**2) pixel_array /= np.max(pixel_array) pixel_array *= np.max(s) img = scat.get_2d_scatter(atoms, pixel_array) print img.shape # plt.imshow(pixel_array) print np.max(img), np.min(img) plt.imshow(img, aspect='auto')
import numpy as np from ase.atoms import Atoms from pyiid.experiments.elasticscatter import ElasticScatter import matplotlib.pyplot as plt from matplotlib.colors import LogNorm import ase.io __author__ = 'christopher' # atoms = Atoms('Au4', [[0, 0, 0], [3, 0, 0], [0, 3, 0], [3, 3, 0]]) atoms = ase.io.read('/mnt/work-data/dev/IID_data/db_test/PDF_LAMMPS_587.traj') scat = ElasticScatter() scat.update_experiment({'qmax': 8, 'qmin': .5}) s = scat.get_scatter_vector() k = 100 i_max, j_max = k, k pixel_array = np.zeros((i_max, j_max)) for i in range(i_max): for j in range(j_max): pixel_array[i, j] = np.sqrt(i ** 2 + j ** 2) pixel_array /= np.max(pixel_array) pixel_array *= np.max(s) img = scat.get_2d_scatter(atoms, pixel_array) print img.shape # plt.imshow(pixel_array) print np.max(img), np.min(img)