コード例 #1
0
ファイル: hdf5_tests.py プロジェクト: khinsen/mosaic-python
    def test_configuration(self):
        M = self.M

        conf = M.Configuration(self.cube_universe,
                               IN.array(NR.normal(size=(40,3))),
                               IN.array(10., N.float64))
        self.assertTrue(is_valid(conf))
        with TestHDF5Store('w') as store:
            self.assertRaises(IOError,
                              lambda : store.store("configuration", conf))
            store.store("universe", self.cube_universe)
            store.store("configuration", conf)
            self.assertTrue(store.retrieve("configuration") is conf)
        with TestHDF5Store('r') as store:
            conf_r = store.retrieve("configuration")
        self.assertFalse(conf_r is conf)
        self.assertTrue(conf_r.is_equivalent(conf))
        self.assertTrue(is_valid(conf_r))

        conf = M.Configuration(self.infinite_universe,
                               IN.array(NR.normal(size=(40,3))),
                               None)
        self.assertTrue(is_valid(conf))
        with TestHDF5Store('w') as store:
            self.assertRaises(IOError,
                              lambda : store.store("configuration", conf))
            store.store("universe", self.infinite_universe)
            store.store("configuration", conf)
            self.assertTrue(store.retrieve("configuration") is conf)
        with TestHDF5Store('r') as store:
            conf_r = store.retrieve("configuration")
        self.assertFalse(conf_r is conf)
        self.assertTrue(conf_r.is_equivalent(conf))
        self.assertTrue(is_valid(conf_r))
コード例 #2
0
ファイル: xml_tests.py プロジェクト: khinsen/mosaic-python
 def test_property(self):
     M = self.M
     universe = self.universe
     for dtype in (N.float32, N.float64):
         for p in [M.AtomProperty(universe, "mass", "amu",
                      IN.array(NR.normal(size=(universe.number_of_atoms,)))),
                   M.SiteProperty(universe, "foo", "",
                      IN.array(NR.normal(size=(universe.number_of_sites, 3)))),
                   M.TemplateAtomProperty(universe, "mass", "amu",
                      IN.array(NR.normal(size=(universe.number_of_template_atoms,
                                               1)))),
                   M.TemplateSiteProperty(universe, "foo", "bar",
                      IN.array(NR.normal(size=(universe.number_of_template_sites,
                                               2, 2)))),
                   ]:
             self.assertTrue(is_valid(p))
             file = StringIO()
             with XMLWriter(file) as writer:
                 writer.store("universe", self.universe)
                 writer.store("property", p)
             xml_string = file.getvalue()
             file = StringIO(xml_string)
             with XMLReader(file) as reader:
                 data = {xml_id: obj for xml_id, obj in reader}
             p_r = data['property']
             self.assertTrue(p_r.is_equivalent(p))
             self.assertTrue(is_valid(p_r))
コード例 #3
0
ファイル: hdf5_tests.py プロジェクト: khinsen/mosaic-python
 def test_property(self):
     M = self.M
     for universe in[self.cube_universe, self.infinite_universe]:
         for p in [M.AtomProperty(universe, "mass", "amu",
                      IN.array(NR.normal(size=(universe.number_of_atoms,)))),
                   M.SiteProperty(universe, "foo", "",
                      IN.array(NR.normal(size=(universe.number_of_sites, 3)))),
                   M.TemplateAtomProperty(universe, "mass", "amu",
                      IN.array(NR.normal(size=(universe.number_of_template_atoms,
                                               1)))),
                   M.TemplateSiteProperty(universe, "foo", "bar",
                      IN.array(NR.normal(size=(universe.number_of_template_sites,
                                               2, 2)))),
                   ]:
             self.assertTrue(is_valid(p))
             with TestHDF5Store('w') as store:
                 self.assertRaises(IOError,
                                   lambda: store.store("property", p))
                 store.store("universe", universe)
                 store.store("property", p)
                 self.assertTrue(store.retrieve("property") is p)
             with TestHDF5Store('r') as store:
                 p_r = store.retrieve("property")
             self.assertFalse(p_r is p)
             self.assertTrue(p_r.is_equivalent(p))
             self.assertTrue(is_valid(p_r))
コード例 #4
0
 def test_properties(self):
     masses = M.TemplateAtomProperty(self.universe, "mass", "amu",
                                     N.array([1., 1., 16.], N.float32))
     self.assertTrue(is_valid(masses))
     self.assertEqual(masses.type, 'template_atom')
     self.assertTrue(masses.universe is self.universe)
     self.assertEqual(masses.element_shape, ())
     self.assertEqual(masses.data.shape, (3,))
     bead_masses = M.TemplateSiteProperty(self.universe, "mass", "amu",
                                          N.array([1., 1.,
                                                   1., 1.,
                                                   8., 8.], N.float32))
     self.assertTrue(is_valid(bead_masses))
     self.assertEqual(bead_masses.type, 'template_site')
     self.assertTrue(bead_masses.universe is self.universe)
     self.assertEqual(bead_masses.element_shape, ())
     self.assertEqual(bead_masses.data.shape, (6,))
     velocities = M.SiteProperty(self.universe, "velocity", "nm ps-1",
                                 dtype=N.float64, element_shape=(3,))
     self.assertTrue(is_valid(velocities))
     self.assertEqual(velocities.type, 'site')
     self.assertTrue(velocities.universe is self.universe)
     self.assertEqual(velocities.data.shape, (60, 3))
     self.assertEqual(velocities.element_shape, (3,))
     foo = M.AtomProperty(self.universe, "foo", "",
                          dtype=N.int16, element_shape=(2, 2))
     self.assertTrue(is_valid(foo))
     self.assertEqual(foo.type, 'atom')
     self.assertTrue(foo.universe is self.universe)
     self.assertEqual(foo.data.shape, (30, 2, 2))
     self.assertEqual(foo.element_shape, (2, 2))
コード例 #5
0
    def test_labels(self):
        labels = tuple(a.name
                       for f, n in self.universe.molecules
                       for a in f.recursive_atom_iterator())
        mm_el = M.TemplateAtomLabel(self.universe, "element", labels)
        el = self.factory(mm_el)
        self.assertTrue(is_valid(el))
        self.assertTrue(el.is_equivalent(mm_el))
        self.assertEqual(el.name, "element")
        self.assertTrue(el.universe.is_equivalent(self.universe))
        self.assertTrue(len(el.strings)
                        == self.universe.number_of_template_atoms)
        for s1, s2 in zip(labels, el.strings):
            self.assertEqual(s1, s2)

        labels = tuple(a.name
                       for f, n in self.universe.molecules
                       for _ in range(n)
                       for a in f.recursive_atom_iterator())
        mm_el = M.AtomLabel(self.universe, "element", labels)
        el = self.factory(mm_el)
        self.assertTrue(is_valid(el))
        self.assertTrue(el.is_equivalent(mm_el))
        self.assertEqual(el.name, "element")
        self.assertTrue(el.universe.is_equivalent(self.universe))
        self.assertTrue(len(el.strings)
                        == self.universe.number_of_atoms)
        for s1, s2 in zip(labels, el.strings):
            self.assertEqual(s1, s2)

        labels = tuple(a.name
                       for f, n in self.universe.molecules
                       for a in f.recursive_atom_iterator()
                       for _ in range(a.number_of_sites))
        mm_el = M.TemplateSiteLabel(self.universe, "element", labels)
        el = self.factory(mm_el)
        self.assertTrue(is_valid(el))
        self.assertTrue(el.is_equivalent(mm_el))
        self.assertEqual(el.name, "element")
        self.assertTrue(el.universe.is_equivalent(self.universe))
        self.assertTrue(len(el.strings)
                        == self.universe.number_of_template_sites)
        for s1, s2 in zip(labels, el.strings):
            self.assertEqual(s1, s2)

        labels = tuple(a.name
                       for f, n in self.universe.molecules
                       for _ in range(n)
                       for a in f.recursive_atom_iterator()
                       for __ in range(a.number_of_sites))
        mm_el = M.SiteLabel(self.universe, "element", labels)
        el = self.factory(mm_el)
        self.assertTrue(is_valid(el))
        self.assertTrue(el.is_equivalent(mm_el))
        self.assertEqual(el.name, "element")
        self.assertTrue(el.universe.is_equivalent(self.universe))
        self.assertTrue(len(el.strings)
                        == self.universe.number_of_sites)
        for s1, s2 in zip(labels, el.strings):
            self.assertEqual(s1, s2)
コード例 #6
0
ファイル: hdf5_tests.py プロジェクト: khinsen/mosaic-python
    def setUp(self):
        TestHDF5Store.initialize()

        M = self.M
        C = M.Element('C')
        H = M.Element('H')
        N = M.Element('N')
        O = M.Element('O')
        peptide_group = M.Fragment('peptide', 'peptide_group',
                                   (),
                                   (M.Atom('CA', C),
                                    M.Atom('HA', H),
                                    M.Atom('H', H),
                                    M.Atom('N', N),
                                    M.Atom('C', C),
                                    M.Atom('O', O)),
                                    (('N', 'H', 'single'),
                                     ('N', 'CA', 'single'),
                                     ('CA', 'HA', 'single'),
                                     ('CA', 'C', 'single'),
                                     ('C', 'O', 'double')))
        ala_sidechain = M.Fragment('sidechain', 'ala_sidechain',
                                   (),
                                   (M.Atom('CB', C),
                                    M.Atom('HB1', H),
                                    M.Atom('HB2', H),
                                    M.Atom('HB3', H)),
                                   (('CB', 'HB1', 'single'),
                                    ('CB', 'HB2', 'single'),
                                    ('CB', 'HB3', 'single'),))
        ala = lambda label: M.Fragment(label, 'alanine',
                                       (copy.copy(peptide_group),
                                        copy.copy(ala_sidechain)),
                                       (),
                                       (('peptide.CA',
                                         'sidechain.CB',
                                         'single'),))
        ala_dipeptide = M.Polymer('di_ala', 'alanine_dipeptide',
                                  (ala('ALA1'), ala('ALA2')),
                                  (('ALA1.peptide.C',
                                    'ALA2.peptide.N',
                                    'single'),),
                                  'polypeptide')
        self.cube_universe = M.Universe('cube', [(ala_dipeptide, 2)],
                                        convention='my_own')
        self.assertTrue(is_valid(self.cube_universe))
        self.infinite_universe = M.Universe('infinite', [(ala_dipeptide, 2)],
                                            convention='my_own')
        self.assertTrue(is_valid(self.infinite_universe))
コード例 #7
0
ファイル: hdf5_tests.py プロジェクト: khinsen/mosaic-python
 def test_universe(self):
     f = mosaic.array_model.Factory()
     for universe in [self.cube_universe, self.infinite_universe]:
         array_universe = f(universe)
         self.assertTrue(is_valid(array_universe))
         with TestHDF5Store('w') as store:
             store.store("universe", array_universe)
             self.assertTrue(store.retrieve("universe") is array_universe)
         with TestHDF5Store('r') as store:
             r_universe = store.retrieve("universe")
         self.assertFalse(r_universe is array_universe)
         self.assertFalse(r_universe is universe)
         self.assertTrue(r_universe.is_equivalent(array_universe))
         self.assertTrue(r_universe.is_equivalent(universe))
         self.assertTrue(is_valid(r_universe))
コード例 #8
0
ファイル: hdf5_tests.py プロジェクト: khinsen/mosaic-python
    def setUp(self):
        TestHDF5Store.initialize()

        M = self.M
        C = M.element('C')
        H = M.element('H')
        N = M.element('N')
        O = M.element('O')
        peptide_group = M.fragment('peptide',
                                   (),
                                   (('CA', M.atom(C)),
                                    ('HA', M.atom(H)),
                                    ('H', M.atom(H)),
                                    ('N', M.atom(N)),
                                    ('C', M.atom(C)),
                                    ('O', M.atom(O))),
                                   (('N', 'H', "single"),
                                    ('N', 'CA', "single"),
                                    ('CA', 'HA', "single"),
                                    ('CA', 'C', "single"),
                                    ('C', 'O', "double")))
        ala_sidechain = M.fragment('ala_sidechain',
                                   (),
                                   (('CB', M.atom(C)),
                                    ('HB1', M.atom(H)),
                                    ('HB2', M.atom(H)),
                                    ('HB3', M.atom(H))),
                                   (('CB', 'HB1', "single"),
                                    ('CB', 'HB2', "single"),
                                    ('CB', 'HB3', "single"),))
        ala = M.fragment('alanine',
                         (('peptide', peptide_group),
                          ('sidechain', ala_sidechain)),
                         (),
                         (('peptide.CA', 'sidechain.CB', "single"),))
        ala_dipeptide = M.polymer('alanine_dipeptide',
                                  (('ALA1', ala),
                                   ('ALA2', ala)),
                                  (('ALA1.peptide.C', 'ALA2.peptide.N', "single"),),
                                  'polypeptide')
        self.cube_universe = M.universe('cube', ((ala_dipeptide, 'di_ala', 2),),
                                        convention='my_own')
        self.assertTrue(is_valid(self.cube_universe))
        self.infinite_universe = M.universe('infinite',
                                            ((ala_dipeptide, 'di_ala', 2),),
                                            convention='my_own')
        self.assertTrue(is_valid(self.infinite_universe))
コード例 #9
0
 def test_basics(self):
     self.assertTrue(is_valid(self.universe))
     self.assertEqual(self.universe.number_of_molecules, 10)
     self.assertEqual(self.universe.number_of_atoms, 30)
     self.assertEqual(self.universe.number_of_sites, 60)
     self.assertEqual(self.universe.number_of_bonds, 20)
     self.assertEqual(self.universe.cell_shape, "infinite")
     self.assertEqual(self.universe.convention, "my_own")
コード例 #10
0
 def test_basic(self):
     mol = self._make_molecule('di_ala')
     self.assertTrue(is_valid(mol))
     self.assertEqual(mol.number_of_atoms, 20)
     self.assertEqual(mol.number_of_sites, 20)
     self.assertEqual(mol.number_of_bonds, 19)
     atoms = [a for a in mol.recursive_atom_iterator()]
     self.assertEqual(mol.number_of_atoms, len(atoms))
     self.assertEqual(mol.polymer_type, "polypeptide")
コード例 #11
0
ファイル: hdf5_tests.py プロジェクト: khinsen/mosaic-python
    def setUp(self):
        TestHDF5Store.initialize()

        M = self.M
        C = M.element('C')
        atom = M.fragment('carbon', (), (('C', M.atom(C)),), ())
        self.cube_universe = M.universe('cube', ((atom, 'carbons', 20),),
                                        convention='my_own')
        self.assertTrue(is_valid(self.cube_universe))
コード例 #12
0
ファイル: xml_tests.py プロジェクト: khinsen/mosaic-python
 def test_selection(self):
     M = self.M
     universe = self.universe
     for s in [M.AtomSelection(universe, IN.array([0], N.uint8)),
               M.SiteSelection(universe, IN.array([1, 2], N.uint8)),
               M.TemplateAtomSelection(universe, IN.array([0, 2], N.uint8)),
               M.TemplateSiteSelection(universe, IN.array([0, 3], N.uint8))]:
         self.assertTrue(is_valid(s))
         file = StringIO()
         with XMLWriter(file) as writer:
             writer.store("universe", self.universe)
             writer.store("selection", s)
         xml_string = file.getvalue()
         file = StringIO(xml_string)
         with XMLReader(file) as reader:
             data = {xml_id: obj for xml_id, obj in reader}
         s_r = data['selection']
         self.assertTrue(s_r.is_equivalent(s))
         self.assertTrue(is_valid(s_r))
コード例 #13
0
ファイル: xml_tests.py プロジェクト: khinsen/mosaic-python
 def test_configuration(self):
     M = self.M
     for dtype in (N.float32, N.float64):
         conf = M.Configuration(self.universe,
                                IN.array(NR.normal(size=(40,3)),
                                         dtype=dtype),
                                IN.array(10., dtype))
         self.assertTrue(is_valid(conf))
         file = StringIO()
         with XMLWriter(file) as writer:
             writer.store("universe", self.universe)
             writer.store("configuration", conf)
         xml_string = file.getvalue()
         file = StringIO(xml_string)
         with XMLReader(file) as reader:
             data = {xml_id: obj for xml_id, obj in reader}
         conf_r = data['configuration']
         self.assertTrue(conf_r.is_equivalent(conf))
         self.assertTrue(is_valid(conf_r))
コード例 #14
0
ファイル: hdf5_tests.py プロジェクト: khinsen/mosaic-python
 def test_selection(self):
     M = self.M
     universe = self.infinite_universe
     for s in [M.AtomSelection(universe, [0]),
               M.SiteSelection(universe, [1, 2]),
               M.TemplateAtomSelection(universe, [0, 3]),
               M.TemplateSiteSelection(universe, [2, 3])]:
         self.assertTrue(is_valid(s))
         with TestHDF5Store('w') as store:
             self.assertRaises(IOError,
                               lambda: store.store("selection", s))
             store.store("universe", universe)
             store.store("selection", s)
             self.assertTrue(store.retrieve("selection") is s)
         with TestHDF5Store('r') as store:
             s_r = store.retrieve("selection")
         self.assertFalse(s_r is s)
         self.assertTrue(s_r.is_equivalent(s))
         self.assertTrue(is_valid(s_r))
コード例 #15
0
ファイル: xml_tests.py プロジェクト: khinsen/mosaic-python
 def test_universe(self):
     file = StringIO()
     with XMLWriter(file) as writer:
         writer.store("universe", self.universe)
     xml_string = file.getvalue()
     file = StringIO(xml_string)
     with XMLReader(file) as reader:
         data = {xml_id: obj for xml_id, obj in reader}
     universe = data['universe']
     self.assertTrue(universe.is_equivalent(self.universe))
     self.assertTrue(is_valid(universe))
コード例 #16
0
ファイル: xml_tests.py プロジェクト: khinsen/mosaic-python
 def test_label(self):
     M = self.M
     universe = self.universe
     for l in [M.AtomLabel(universe, "element",
                           tuple(a.name
                                 for f, n in universe.molecules
                                 for _ in range(n)
                                 for a in f.recursive_atom_iterator())),
               M.TemplateAtomLabel(universe, "element",
                                   tuple(a.name
                                         for f, n in universe.molecules
                                         for a in f.recursive_atom_iterator())),
               M.SiteLabel(universe, "element",
                           tuple(a.name
                                 for f, n in self.universe.molecules
                                 for _ in range(n)
                                 for a in f.recursive_atom_iterator()
                                 for __ in range(a.number_of_sites))),
               M.TemplateSiteLabel(universe, "element",
                                   tuple(a.name
                                         for f, n in self.universe.molecules
                                         for a in f.recursive_atom_iterator()
                                         for _ in range(a.number_of_sites))),
               ]:
         self.assertTrue(is_valid(l))
         file = StringIO()
         with XMLWriter(file) as writer:
             writer.store("universe", self.universe)
             writer.store("label", l)
         xml_string = file.getvalue()
         file = StringIO(xml_string)
         with XMLReader(file) as reader:
             data = {xml_id: obj for xml_id, obj in reader}
         l_r = data['label']
         self.assertTrue(l_r.is_equivalent(l))
         self.assertTrue(is_valid(l_r))
コード例 #17
0
ファイル: hdf5_tests.py プロジェクト: khinsen/mosaic-python
 def test_label(self):
     M = self.M
     for universe in[self.cube_universe, self.infinite_universe]:
         for l in [M.AtomLabel(universe, "element",
                               tuple(a.name
                                     for f, n in universe.molecules
                                     for _ in range(n)
                                     for a in f.recursive_atom_iterator())),
                   M.TemplateAtomLabel(universe, "element",
                                       tuple(a.name
                                             for f, n in universe.molecules
                                             for a in f.recursive_atom_iterator())),
                   M.SiteLabel(universe, "element",
                               tuple(a.name
                                     for f, n in universe.molecules
                                     for _ in range(n)
                                     for a in f.recursive_atom_iterator()
                                     for __ in range(a.number_of_sites))),
                   M.TemplateSiteLabel(universe, "element",
                                       tuple(a.name
                                             for f, n in universe.molecules
                                             for a in f.recursive_atom_iterator()
                                             for _ in range(a.number_of_sites))),
                   ]:
             self.assertTrue(is_valid(l))
             with TestHDF5Store('w') as store:
                 self.assertRaises(IOError,
                                   lambda: store.store("label", l))
                 store.store("universe", universe)
                 store.store("label", l)
                 self.assertTrue(store.retrieve("label") is l)
             with TestHDF5Store('r') as store:
                 l_r = store.retrieve("label")
             self.assertFalse(l_r is l)
             self.assertTrue(l_r.is_equivalent(l))
             self.assertTrue(is_valid(l_r))