Ejemplo n.º 1
0
 def test_configuration(self):
     mol = make_water_fragment()
     universe = M.universe('cube', [(mol, 'water', 10)])
     # Missing data
     self.assertRaises(TypeError,
                       lambda: M.Configuration(universe))
     # Positions but no cell parameters
     self.assertRaises(TypeError,
                       lambda: M.Configuration(universe,
                                               IN.zeros((30, 3), N.float32)))
     # Positions and cell parameters of different dtype
     self.assertRaises(ValueError,
                       lambda: M.Configuration(universe,
                                               IN.zeros((30, 3), N.float32),
                                               N.float64(10.)))
     # Positions not an array
     self.assertRaises(TypeError,
                       lambda: M.Configuration(universe,
                                               list(IN.zeros((30, 3),
                                                            N.float32)),
                                               N.float32(10.)))
     # Positions of wrong shape
     self.assertRaises(ValueError,
                       lambda: M.Configuration(universe,
                                               IN.zeros((25, 3), N.float32),
                                               N.float32(10.)))
     # Cell parameters of wrong shape
     self.assertRaises(ValueError,
                       lambda: M.Configuration(universe,
                                               IN.zeros((30, 3), N.float32),
                                               IN.zeros((3,), N.float32)))
Ejemplo n.º 2
0
 def test_parallelepiped(self):
     universe = M.universe('parallelepiped', [(water, 'water', 100)])
     nsites = universe.number_of_sites
     conf1 = M.Configuration(universe,
                             IN.array(NR.normal(size=(nsites, 3))),
                             IN.array(NR.normal(size=(3, 3))))
     conf2 = M.Configuration(universe,
                             IN.array(NR.normal(size=(nsites, 3))),
                             IN.array(NR.normal(size=(3, 3))))
     self._write_and_read_back(universe, conf1, conf2)
Ejemplo n.º 3
0
 def test_cubic(self):
     universe = M.universe('cube', [(water, 'water', 10)])
     nsites = universe.number_of_sites
     conf1 = M.Configuration(universe,
                             IN.array(NR.normal(size=(nsites, 3))),
                             IN.array(10., N.float64))
     conf2 = M.Configuration(universe,
                             IN.array(NR.normal(size=(nsites, 3))),
                             IN.array(11., N.float64))
     self._write_and_read_back(universe, conf1, conf2)
Ejemplo n.º 4
0
 def test_infinite(self):
     universe = M.universe('infinite', [(water, 'water', 5)])
     nsites = universe.number_of_sites
     conf1 = M.Configuration(universe,
                             IN.array(NR.normal(size=(nsites, 3))),
                             None)
     conf2 = M.Configuration(universe,
                             IN.array(NR.normal(size=(nsites, 3))),
                             None)
     self._write_and_read_back(universe, conf1, conf2)
Ejemplo n.º 5
0
 def _read_universe(self, el):
     ref = el.get('ref', None)
     if ref is not None:
         return self._get_data(ref)
     molecules = \
       tuple(self._parse_molecule(el_m)
             for el_m in el.iter('molecule'))
     symmetry_transformations = \
       tuple((self._array((3, 3), N.float64, el_t.find('rotation').text),
              self._array((3,), N.float64, el_t.find('translation').text))
             for el_t in el.iter('transformation'))
     return im.universe(el.get('cell_shape'),
                        molecules,
                        symmetry_transformations,
                        el.get('convention'))
Ejemplo n.º 6
0
 def test_universe(self):
     mol = M.fragment("water", (),
                      (("H1", M.atom(M.element("H"), 8)),
                       ("H2", M.atom(M.element("H"), 8)),
                       ("O",  M.atom(M.element("O"), 2))),
                      (("H1", "O", "single"), ("H2", "O", "single")))
     self.assertRaises(TypeError,
                       lambda: M.universe(0, [(mol, 'water', 10)]))
     self.assertRaises(ValueError,
                       lambda: M.universe('strange', [(mol, 'water', 10)]))
     self.assertRaises(ValueError,
                       lambda: M.universe('strange', [(mol, 10)]))
     self.assertRaises(TypeError,
                       lambda: M.universe('infinite', mol))
     self.assertRaises(ValueError,
                       lambda: M.universe('infinite', [("water", 10)]))
     self.assertRaises(TypeError,
                       lambda: M.universe('infinite', [mol]))
     self.assertRaises(ValueError,
                       lambda: M.universe('infinite', [(10, mol)]))
     self.assertRaises(ValueError,
                       lambda: M.universe('infinite', [(mol, 'water', 10)],
                                          [(IN.zeros((3,3), N.float64),
                                            IN.zeros((3,), N.float64))]))
Ejemplo n.º 7
0
 def test_selection(self):
     mol = make_water_fragment(nsites=2)
     universe = M.universe('cube', [(mol, 'water', 5)])
     # Index occurs twice
     self.assertRaises(ValueError,
                       lambda: M.AtomSelection(universe,
                                               IN.zeros((2,), N.uint16)))
     # Atom index too large
     self.assertRaises(ValueError,
                       lambda: M.AtomSelection(universe,
                                               IN.array([20], N.uint16)))
     # Template atom index too large
     self.assertRaises(ValueError,
                       lambda: M.TemplateAtomSelection(universe,
                                                       IN.array([3], N.uint8)))
     # Site index too large
     self.assertRaises(ValueError,
                       lambda: M.SiteSelection(universe,
                                               IN.array([40], N.uint16)))
     # Template site index too large
     self.assertRaises(ValueError,
                       lambda: M.TemplateSiteSelection(universe,
                                                       IN.array([8], N.uint8)))
Ejemplo n.º 8
0
 def setUp(self):
     self.infinite = M.universe('infinite', ())
     self.cube = M.universe('cube', ())
     self.cuboid = M.universe('cuboid', ())
     self.parallelepiped = M.universe('parallelepiped', ())
Ejemplo n.º 9
0
 def setUp(self):
     mol = make_water_fragment(2)
     self.universe = M.universe('infinite', [(mol, 'water', 10)],
                                convention='my_own')