示例#1
0
    def test_convert_to_dict_and_rebuild(self):
        '''test_convert_to_dict_and_rebuild
        '''
        top = self.traj.top
        d = top.to_dict()

        new_top = pt.Topology()

        MOLNUM = 0

        for idx, (aname, atype, charge, mass, resid, resname,
                  mol_number) in enumerate(
                      zip(d['atom_name'], d['atom_type'], d['atom_charge'], d[
                          'atom_mass'], d['resid'], d['resname'], d[
                              'mol_number'])):
            atom = pt.core.Atom(
                name=aname, type=atype, charge=charge, mass=mass, resid=resid)
            atom.set_mol(mol_number)
            residue = pt.core.Residue(resname, resid)
            new_top.add_atom(atom, residue)
            if idx == 0:
                new_top.start_new_mol()
            if mol_number > MOLNUM:
                new_top.start_new_mol()
                MOLNUM += 1

        new_top.add_bonds(d['bond_index'])
        new_top.add_dihedrals(d['dihedral_index'])
        new_top.box = Box(top.box.values)

        assert_equal_topology(top, new_top, self.traj)
    def test_comprehensive(self):
        traj = pt.iterload("data/Test_RemdTraj/rem.nc.000",
                           "data/Test_RemdTraj/ala2.99sb.mbondi2.parm7")
        # temperature
        aa_eq(traj.temperatures, [300., 630.5, 630.5, 630.5, 630.5, 630.5,
                                  630.5, 630.5, 492.2, 384.3])

        # iterframe (already in doctest), just throwing raise to increase coverage score
        self.assertRaises(ValueError, lambda: traj.iterframe(rmsfit='crazy'))

        # raise
        # memory error if load larger than 1GB for xyz
        traj = pt.datafiles.load_tz2_ortho()
        for _ in range(11):
            traj._load(traj.filelist)

        self.assertRaises(MemoryError, lambda: traj.xyz)

        # can not find filename
        self.assertRaises(ValueError, lambda: traj._load(None))
        # has filename but does not have Topology
        self.assertRaises(
            ValueError,
            lambda: pt.TrajectoryIterator("data/Test_RemdTraj/rem.nc.000", top=None))
        self.assertRaises(
            ValueError,
            lambda: pt.TrajectoryIterator("data/Test_RemdTraj/rem.nc.000"))
        # empty Topology
        self.assertRaises(
            ValueError,
            lambda: pt.TrajectoryIterator("data/Test_RemdTraj/rem.nc.000", top=pt.Topology()))
        # weird Topology
        self.assertRaises(
            ValueError,
            lambda: pt.TrajectoryIterator("data/Test_RemdTraj/rem.nc.000", top=pt.Frame))
示例#3
0
    def test_raise_construtor(self):
        self.assertRaises(ValueError, lambda: pt.Trajectory(pt.trajectory))
        # raise if filename is not string or list of string
        empty_traj = pt.Trajectory()
        empty_traj.top = pt.datafiles.load_tz2()[:].top
        self.assertRaises(ValueError, lambda: empty_traj.load(pt.Trajectory))

        # raise if empty Topology
        xyz = np.arange(90).astype('f8').reshape(3, 10, 3)
        self.assertRaises(ValueError, lambda: pt.Trajectory(xyz=xyz, top=pt.Topology()))
示例#4
0
    def test_comprehensive(self):
        traj = pt.iterload(fn('Test_RemdTraj/rem.nc.000'),
                           fn('Test_RemdTraj/ala2.99sb.mbondi2.parm7'))
        # temperature
        aa_eq(traj.temperatures, [
            300., 630.5, 630.5, 630.5, 630.5, 630.5, 630.5, 630.5, 492.2, 384.3
        ])

        # iterframe (already in doctest), just throwing raise to increase coverage score
        self.assertRaises(ValueError, lambda: traj.iterframe(rmsfit='crazy'))

        # raise
        # memory error if load larger than 1GB for xyz
        traj = pt.datafiles.load_tz2_ortho()
        for _ in range(2):
            traj._load(traj.filelist)

        with patch('pytraj.trajectory.trajectory_iterator.TrajectoryIterator._estimated_GB') as \
                mem:

            def mock_get(*args, **kwargs):
                return 10000000

            mem.__get__ = mock_get
            self.assertRaises(MemoryError, lambda: traj.xyz)

        # can not find filename
        self.assertRaises(ValueError, lambda: traj._load(None))
        # has filename but does not have Topology
        self.assertRaises(
            ValueError,
            lambda: pt.TrajectoryIterator(fn('Test_RemdTraj/rem.nc.000'),
                                          top=None))
        self.assertRaises(
            ValueError,
            lambda: pt.TrajectoryIterator(fn('Test_RemdTraj/rem.nc.000')))
        # empty Topology
        self.assertRaises(
            ValueError,
            lambda: pt.TrajectoryIterator(fn('Test_RemdTraj/rem.nc.000'),
                                          top=pt.Topology()))
        # weird Topology
        self.assertRaises(
            ValueError,
            lambda: pt.TrajectoryIterator(fn('Test_RemdTraj/rem.nc.000'),
                                          top=pt.Frame))