def test_default_graph_periodic(self): molecule = Molecule.from_file("input/lau.xyz") uc = UnitCell.from_parameters3( numpy.array([14.587, 12.877, 7.613])*angstrom, numpy.array([90.000, 111.159, 90.000])*deg ) uc = uc.alignment_c*uc molecule = molecule.copy_with(unit_cell=uc) molecule.set_default_graph() self.assertEqual(molecule.graph.num_edges, 4*molecule.size/3)
def test_parameters(self): for counter in xrange(100): in_lengths = numpy.random.uniform(0.5, 1, (3,)) in_angles = numpy.random.uniform(0.3, numpy.pi/2, (3,)) try: uc = UnitCell.from_parameters3(in_lengths, in_angles) except ValueError, e: continue out_lengths, out_angles = uc.parameters self.assertArraysAlmostEqual(in_lengths, out_lengths) self.assertArraysAlmostEqual(in_angles, out_angles)
def iter_unit_cells(unit_cell_str, sub=None): sub = fix_slice(sub) if len(unit_cell_str) == 0: uc = UnitCell( numpy.array([[1,0,0],[0,1,0],[0,0,1]], float), numpy.array([False,False,False]), ) while True: yield uc if "," in unit_cell_str: parameters = list(parse_unit(word) for word in unit_cell_str.split(",") if len(word) > 0) if len(parameters) == 1: a= parameters[0] uc = UnitCell( numpy.array([[a,0,0],[0,a,0],[0,0,a]], float), numpy.array([True, True, True]), ) elif len(parameters) == 3: a,b,c = parameters uc = UnitCell( numpy.array([[a,0,0],[0,b,0],[0,0,c]], float), numpy.array([True, True, True]), ) elif len(parameters) == 6: a,b,c,alpha,beta,gamma = parameters uc = UnitCell.from_parameters3( numpy.array([a,b,c]), numpy.array([alpha,beta,gamma]) ) elif len(parameters) == 9: uc = UnitCell( numpy.array(parameters, float).reshape((3,3)), numpy.array([True, True, True]), ) else: raise ValueError("If the --cell option contains comma's, one, three, six or nine value(s) are expected.") while True: yield uc else: filenames = ["%s.%s" % (unit_cell_str, suffix) for suffix in ["a.x", "a.y", "a.z", "b.x", "b.y", "b.z", "c.x", "c.y", "c.z"]] dtype = numpy.dtype([("cell", float, (3,3))]) mtr = MultiTracksReader(filenames, dtype, sub=sub) for row in mtr: yield UnitCell( numpy.array(row["cell"], float), numpy.array([True, True, True]), )
def test_distances_intra_lau_periodic(self): coordinates = XYZFile("input/lau.xyz").geometries[0] cutoff = periodic.max_radius*2 unit_cell = UnitCell.from_parameters3( numpy.array([14.59, 12.88, 7.61])*angstrom, numpy.array([ 90.0, 111.0, 90.0])*deg, ) pair_search = PairSearchIntra(coordinates, cutoff, unit_cell) self.verify_bins_intra_periodic(pair_search.bins) distances = [ (frozenset([i0, i1]), distance) for i0, i1, delta, distance in pair_search ] self.verify_distances_intra(coordinates, cutoff, distances, unit_cell)