示例#1
0
    def test_read_comment(self):
        comment = random_comment()
        num_atoms = random.randint(1,100)
        crds = random_crds(num_atoms)

        with tfu.TempfileSession() as tfs:
            file_name = tfs.temp_file_name('.crd')

            with mdcrd.open(file_name, 'w', num_atoms=num_atoms,
                            comment=comment) as f:
                f.write(crds)

            with mdcrd.open(file_name, 'r', num_atoms=num_atoms) as f:
                self.assertEqual(f.comment, comment)
示例#2
0
    def test_read_comment(self):

        with open(test_file('expected_ala_comment')) as f:
            expected_comment = f.next()

        with mdcrd.open(test_file('ala'), num_atoms=22) as f:
            self.assertEqual(f.comment, expected_comment)
示例#3
0
    def test_read_crd(self):
        with open(test_file('expected_ala_crds')) as f:
            expected_crds = [float(x) for x in f.read().split()]

        with mdcrd.open(test_file('ala'), num_atoms=22) as f:
            crds = f.next()

        for (expected, crd) in it.izip_longest(expected_crds, crds):
            self.assertAlmostEqual(expected, crd, 3)
示例#4
0
    def test_read_crds(self):
        comment = random_comment()
        num_atoms = random.randint(1,100)

        num_crds = random.randint(1, 10)
        crdss = [random_crds(num_atoms) for count in xrange(num_crds)]

        with tfu.TempfileSession() as tfs:
            file_name = tfs.temp_file_name('.crd')

            with mdcrd.open(file_name, 'w', num_atoms=num_atoms,
                            comment=comment) as f:

                for crds in crdss:
                    f.write(crds)

            with mdcrd.open(file_name, 'r', num_atoms=num_atoms) as f:
                for expected_crds, read_crds in it.izip_longest(crdss, f):
                    self.assertNotEqual(expected_crds, None)
                    self.assertNotEqual(read_crds, None)
                    for (expected, crd) in it.izip_longest(expected_crds, read_crds):
                        self.assertAlmostEqual(expected, crd, 3)