def test_sk_partial(self): # TODO: this test fails with python 3 (small deviations) f = os.path.join(self.reference_path, 'kalj-small.xyz') ref_value = { 'A': numpy.array([0.078218, 2.896436, 0.543363]), 'B': numpy.array([0.867164, 0.869868, 0.981121]), 'AB': numpy.array([-0.1907, 0.399360, 0.050480]) } for species in ['A', 'B']: with trajectory.TrajectoryXYZ(f) as t: t.add_callback(filter_species, species) p = postprocessing.StructureFactor(t, [4, 7.3, 10]) p.compute() self.assertLess(deviation(p.value, ref_value[species]), 1e-2) with trajectory.TrajectoryXYZ(f) as t: sk = postprocessing.Partial(postprocessing.StructureFactor, ['A', 'B'], t, [4, 7.3, 10]) sk.compute() self.assertLess( deviation(sk.partial[('A', 'A')].value, ref_value['A']), 1e-2) self.assertLess( deviation(sk.partial[('B', 'B')].value, ref_value['B']), 1e-2) self.assertLess( deviation(sk.partial[('A', 'B')].value, ref_value['AB']), 1e-2)
def test_sk_random(self): f = os.path.join(self.reference_path, 'kalj-small.xyz') t = trajectory.TrajectoryXYZ(f) t.add_callback(filter_random, 75) p = postprocessing.StructureFactor(t, [4, 7.3, 10, 30.0], nk=40) p.compute() t.close()
def test_sk_fixgrid(self): # TODO: this test fails with python 3 (small deviations) f = os.path.join(self.reference_path, 'kalj-small.xyz') t = trajectory.TrajectoryXYZ(f) p = postprocessing.StructureFactor(t, [4, 7.3, 10]) p.compute() ref_value = numpy.array( [0.083411717745282138, 2.76534619194135, 0.67129958432631986]) self.assertLess(deviation(p.value, ref_value), 0.04)
def test_sk_variable_cell(self): # TODO: this test has no assertion def deformation(s, scale=0.01): # Note this random scaling changes every time read is called, # even for the same sample x = 1 + (random.random() - 0.5) * scale s.cell.side *= x for p in s.particle: p.position *= x return s f = os.path.join(self.reference_path, 'kalj-small.xyz') with trajectory.TrajectoryXYZ(f) as t: p = postprocessing.StructureFactor(t, list(range(1, 10))) p.compute() with trajectory.TrajectoryXYZ(f) as t: t.add_callback(deformation, 1e-3) p = postprocessing.StructureFactor(t, list(range(1, 10))) p.compute()
def test_sk_update(self): f = os.path.join(self.reference_path, 'kalj-small.xyz') t = trajectory.TrajectoryXYZ(f) p = postprocessing.StructureFactor(t, kmin=-1, kmax=4, ksamples=3, dk=0.2) p.do(update=False) p = postprocessing.StructureFactor(t, kmin=-1, kmax=4, ksamples=3, dk=0.2) p.do(update=True) ref_value = numpy.array( [0.075820086512828039, 0.065300213310725302, 0.082485082309989494]) self.assertLess(deviation(p.value, ref_value), 0.04) t.close()
def test_sk_field(self): """ Test that S(k) with a field that is 0 if id=A and 1 if id=B gives the BB partial structure factor. """ # TODO: this test fails with python 3 because of a weird issue with xyz trajectory in atooms (_fallback) f = os.path.join(self.reference_path, 'kalj-small.xyz') ff = os.path.join(self.reference_path, 'kalj-small-field.xyz') t = trajectory.TrajectoryXYZ(f) p = postprocessing.StructureFactor(t, [4, 7.3, 10], trajectory_field=ff) p.compute() # We multiply by x because the S(k) is normalized to 1/N from atooms.system.particle import composition x = composition(t[0].particle)['B'] / float(len(t[0].particle)) ref_value = x * numpy.array( [0.86716496871363735, 0.86986885176760842, 0.98112175463699136]) self.assertLess(deviation(p.value, ref_value), 1e-2)
def test_sk_field(self): """ Test that S(k) with a field that is 0 if id=A and 1 if id=B gives the BB partial structure factor. """ f = os.path.join(self.reference_path, 'kalj-small.xyz') ff = os.path.join(self.reference_path, 'kalj-small-field.xyz') th = trajectory.TrajectoryXYZ(f) tt = trajectory.TrajectoryXYZ(ff) p = postprocessing.StructureFactor(th, [4, 7.3, 10]) p.add_weight(trajectory=tt, field='field_B') p.compute() # We multiply by x because the S(k) is normalized to 1/N from atooms.system.particle import composition x = composition(th[0].particle)['B'] / float(len(th[0].particle)) ref_value = x * numpy.array( [0.86716496871363735, 0.86986885176760842, 0.98112175463699136]) self.assertLess(deviation(p.value, ref_value), 1e-2) th.close() tt.close()