コード例 #1
0
ファイル: unit_cell.py プロジェクト: woutersmet/Molmodsummer
 def test_set(self):
     #print
     for counter in xrange(100):
         #print counter
         uc = UnitCell()
         uc.cell = numpy.random.uniform(-1, 1, (3, 3))
         in_lengths = numpy.random.uniform(0.5, 1, (3,))
         in_angles = numpy.random.uniform(0.3, math.pi/2, (3,))
         #print
         #print " === IN === "
         #print in_lengths
         #print in_angles
         det_before = numpy.linalg.det(uc.cell)
         try:
             uc.set_parameters(in_lengths, in_angles)
         except ValueError, e:
             #print
             #print e.__class__
             #print e
             #print in_lengths
             #print in_angles/math.pi*180
             #print "-"*20
             continue
         det_after = numpy.linalg.det(uc.cell)
         #print " === OUT === "
         out_lengths, out_angles = uc.get_parameters()
         #print out_lengths
         #print out_angles
         self.assertAlmostEqual(sum((in_lengths - out_lengths)**2), 0.0, 5, "Lengths mismatch.")
         self.assertAlmostEqual(sum((in_angles - out_angles)**2), 0.0, 5, "Angles mismatch: %s and %s" % (in_angles, out_angles))
         self.assert_(det_before * det_after > 0, "Handedness has changed.")
コード例 #2
0
ファイル: unit_cell.py プロジェクト: woutersmet/Molmodsummer
 def test_radius_indexes(self):
     cell = numpy.array([
         [1.5, 0, 0],
         [0, 1.5, 0],
         [0, 0, 1.5],
     ], float)
     uc = UnitCell(cell, numpy.array([True, True, True]))
     self.assert_((uc.get_radius_ranges(3.1)==3).all())
     self.assertEqual(len(uc.get_radius_indexes(3.1)), 81)
コード例 #3
0
 def test_radius_indexes(self):
     cell = numpy.array([
         [1.5, 0, 0],
         [0, 1.5, 0],
         [0, 0, 1.5],
     ], float)
     uc = UnitCell(cell, numpy.array([True, True, True]))
     self.assert_((uc.get_radius_ranges(3.1) == 3).all())
     self.assertEqual(len(uc.get_radius_indexes(3.1)), 81)
コード例 #4
0
ファイル: unit_cell.py プロジェクト: woutersmet/Molmodsummer
 def test_shortest_vector(self):
     for uc_counter in xrange(10):
         #print counter
         uc = UnitCell()
         uc.cell = numpy.random.uniform(-1, 1, (3, 3))
         uc.update_reciproke()
         for r_counter in xrange(10):
             r0 = numpy.random.normal(0, 10, 3)
             r1 = uc.shortest_vector(r0)
             self.assert_(numpy.linalg.norm(r0) <= numpy.linalg.norm(r1))
コード例 #5
0
ファイル: tube.py プロジェクト: woutersmet/Zeo_thesis
        def create_pattern():
            "Read the atom positions and transform them to the flat coordinates"
            active, inactive = universe.get_active_inactive()
            tmp_cell = UnitCell()
            tmp_cell.add_cell_vector(universe.cell[:,active[0]])
            tmp_cell.add_cell_vector(universe.cell[:,active[1]])
            r = tmp_cell.calc_align_rotation_matrix()

            return [
                (atom.number, numpy.dot(r, atom.get_absolute_frame().t))
                for atom in yield_atoms([universe])
            ]
コード例 #6
0
ファイル: binning.py プロジェクト: woutersmet/Molmodsummer
    def test_distances_intra_periodic(self):
        molecule, binned_atoms = self.load_binned_atoms("lau.xyz")
        unit_cell = UnitCell()
        unit_cell.set_parameters(
            numpy.array([14.59, 12.88, 7.61])*angstrom,
            numpy.array([ 90.0, 111.0, 90.0])*degree,
        )

        distances = dict(
            (frozenset([positioned1.id, positioned2.id]), result)
            for (positioned1, positioned2), result
            in IntraAnalyseNeighboringObjects(binned_atoms, self.compare_function)(unit_cell)
        )
        self.verify_intra(molecule, distances, unit_cell)
コード例 #7
0
 def test_add_periodicities(self):
     for counter in xrange(100):
         #print counter
         uc = UnitCell()
         uc.cell = numpy.random.uniform(-1, 1, (3, 3))
         uc.cell_active[:] = False
         uc.add_cell_vector(numpy.random.uniform(-2, 2, 3))
         uc.add_cell_vector(numpy.random.uniform(-2, 2, 3))
         uc.add_cell_vector(numpy.random.uniform(-2, 2, 3))
コード例 #8
0
ファイル: unit_cell.py プロジェクト: woutersmet/Molmodsummer
 def test_add_periodicities(self):
     for counter in xrange(100):
         #print counter
         uc = UnitCell()
         uc.cell = numpy.random.uniform(-1, 1, (3, 3))
         uc.cell_active[:] = False
         uc.add_cell_vector(numpy.random.uniform(-2,2,3))
         uc.add_cell_vector(numpy.random.uniform(-2,2,3))
         uc.add_cell_vector(numpy.random.uniform(-2,2,3))
コード例 #9
0
 def test_set(self):
     #print
     for counter in xrange(100):
         #print counter
         uc = UnitCell()
         uc.cell = numpy.random.uniform(-1, 1, (3, 3))
         in_lengths = numpy.random.uniform(0.5, 1, (3, ))
         in_angles = numpy.random.uniform(0.3, math.pi / 2, (3, ))
         #print
         #print " === IN === "
         #print in_lengths
         #print in_angles
         det_before = numpy.linalg.det(uc.cell)
         try:
             uc.set_parameters(in_lengths, in_angles)
         except ValueError, e:
             #print
             #print e.__class__
             #print e
             #print in_lengths
             #print in_angles/math.pi*180
             #print "-"*20
             continue
         det_after = numpy.linalg.det(uc.cell)
         #print " === OUT === "
         out_lengths, out_angles = uc.get_parameters()
         #print out_lengths
         #print out_angles
         self.assertAlmostEqual(sum((in_lengths - out_lengths)**2), 0.0, 5,
                                "Lengths mismatch.")
         self.assertAlmostEqual(
             sum((in_angles - out_angles)**2), 0.0, 5,
             "Angles mismatch: %s and %s" % (in_angles, out_angles))
         self.assert_(det_before * det_after > 0, "Handedness has changed.")
コード例 #10
0
 def test_shortest_vector(self):
     for uc_counter in xrange(10):
         #print counter
         uc = UnitCell()
         uc.cell = numpy.random.uniform(-1, 1, (3, 3))
         uc.update_reciproke()
         for r_counter in xrange(10):
             r0 = numpy.random.normal(0, 10, 3)
             r1 = uc.shortest_vector(r0)
             self.assert_(numpy.linalg.norm(r0) <= numpy.linalg.norm(r1))
コード例 #11
0
ファイル: composed.py プロジェクト: woutersmet/Zeo_thesis
 def convert_to_value(self, representation):
     lengths, angles = ComposedInTable.convert_to_value(self, representation)
     unit_cell = UnitCell(self.saved_value)
     unit_cell.set_parameters(lengths, angles)
     return unit_cell.cell
コード例 #12
0
ファイル: composed.py プロジェクト: woutersmet/Zeo_thesis
 def convert_to_representation(self, value):
     unit_cell = UnitCell(value)
     self.saved_value = value
     lengths, angles = unit_cell.get_parameters()
     return ComposedInTable.convert_to_representation(self, (lengths, angles))