def test_simple(self):
        """Simple complete run of get_glyc_restraint"""
        with utils.temporary_directory() as tmpdir:
            with open(os.path.join(tmpdir, 'test-allosmod.py'), 'w') as fh:
                fh.write("""line 1
def special_patches(self, aln):
    self.patch(residue_type='NGLB', residues=(self.residues['1:A'],
                                              self.residues['2:B']))
line 2
""")
            with open(os.path.join(tmpdir, 'test.pdb'), 'w') as fh:
                fh.write("""
ATOM      1  N   ALA A   1      17.807  17.608   5.019  1.00 17.18           N
ATOM      2  CA  ALA A   1      17.121  17.162   6.197  1.00 15.60           C
ATOM      3  C   ALA A   1      18.085  17.018   7.343  1.00 14.54           C
ATOM      4  O   ALA A   1      19.244  16.654   7.119  1.00 15.42           O
HETATM    5  O1  BMA B   2      19.244  16.654   7.119  1.00 15.42           O
HETATM    6  C1  BMA B   2      19.244  16.654   7.119  1.00 15.42           O
""")
            out = check_output(['allosmod', 'get_glyc_restraint', 'test.pdb',
                                'test-allosmod.py'], stderr=subprocess.STDOUT,
                               retcode=0, universal_newlines=True, cwd=tmpdir)
            # One restraint between CA and C1:
            self.assertEqual(out, 'R    3   1   1   1   2   2   1        '
                                  '2     6    5.0000    0.0350\n')
            # special_patches should have been removed from .py file:
            with open(os.path.join(tmpdir, 'test-allosmod.py')) as fh:
                contents = fh.read()
            self.assertEqual(contents, 'line 1\nline 2\n')
Esempio n. 2
0
    def test_simple(self):
        """Simple complete run of bin_data"""
        with utils.temporary_directory() as tmpdir:
            testdata = os.path.join(tmpdir, 'test.data')
            with open(testdata, 'w') as fh:
                fh.write("""1.0 10
1.1 10
1.2 10
1.2 10
2.0\t20
3.0 30
4.0 40
5.0 50
6.0 60
""")
            out = check_output(['allosmod', 'bin_data', 'test.data', '0', 'm1',
                                '10', '20'],
                               universal_newlines=True, cwd=tmpdir)
            self.assertEqual(out, """0.92500 0.44444 4.00000
2.02500 0.11111 1.00000
3.12500 0.11111 1.00000
4.22500 0.11111 1.00000
4.77500 0.11111 1.00000
5.87500 0.11111 1.00000
""")
            out = check_output(['allosmod', 'bin_data', 'test.data', '1', 'm1',
                                '10', '20'],
                               universal_newlines=True, cwd=tmpdir)
            self.assertEqual(out, "9.72500 1.00000 4.00000\n")
Esempio n. 3
0
 def test_insert_fail(self):
     """Test align.insert_gap() failure"""
     with utils.temporary_directory() as tmpdir:
         ali = os.path.join(tmpdir, 'test_insert.ali')
         with open(ali, 'w') as fh:
             fh.write(TEST_ALIGNMENT)
         self.assertRaises(ValueError, allosmod.util.align.insert_gap,
                           ali, 1, 97, 99)
Esempio n. 4
0
 def test_make_ligand_file(self):
     """Test make_ligand_file() function"""
     with utils.temporary_directory() as tmpdir:
         fname = os.path.join(tmpdir, 'ligands.ids')
         cryptosite.patch_mapper.make_ligand_file(fname)
         with open(fname) as fh:
             lines = fh.readlines()
         self.assertEqual(len(lines), 16)
Esempio n. 5
0
 def test_make_ligand_file(self):
     """Test make_ligand_file() function"""
     with utils.temporary_directory() as tmpdir:
         fname = os.path.join(tmpdir, 'ligands.ids')
         cryptosite.patch_mapper.make_ligand_file(fname)
         with open(fname) as fh:
             lines = fh.readlines()
         self.assertEqual(len(lines), 16)
 def test_simple(self):
     """Simple complete run of count_alignments"""
     with utils.temporary_directory() as tmpdir:
         self.setup_inputs(tmpdir)
         out = check_output(['allosmod', 'count_alignments',
                             'align.ali', 'templates', 'pm.pdb'],
                            universal_newlines=True, cwd=tmpdir)
         self.assertEqual(out.rstrip('\r\n'), "2")
Esempio n. 7
0
 def test_detect_invalid_residue_types_ok(self):
     """Test _detect_invalid_residue_types() with OK sequence"""
     with utils.temporary_directory() as tmpdir:
         fname = os.path.join(tmpdir, 'test.pdb')
         with open(fname, 'w') as fh:
             fh.write(pdb_line + '\n')
         e = modeller.environ()
         m = modeller.model(e, file=fname)
     cleaning._detect_invalid_residue_types(m)
 def test_count_alignments(self):
     """Test count_alignments function"""
     from allosmod.count_alignments import count_alignments
     with utils.temporary_directory() as tmpdir:
         self.setup_inputs(tmpdir)
         num_align, num_res = count_alignments(
                                   os.path.join(tmpdir, "align.ali"),
                                   "pm.pdb", ["5fd1", "1bqx"])
         self.assertEqual(num_align, 113)
         self.assertEqual(num_res, 57)
Esempio n. 9
0
 def test_insert(self):
     """Test align.insert_gap()"""
     with utils.temporary_directory() as tmpdir:
         ali = os.path.join(tmpdir, 'test_insert.ali')
         with open(ali, 'w') as fh:
             fh.write(TEST_ALIGNMENT)
         s_out = StringIO()
         allosmod.util.align.insert_gap(ali, 1, 7, 9, s_out)
         out_lines = s_out.getvalue().split('\n')
         self.assertEqual(out_lines[2], 'N/T--TVFQG---VAGQSLQ')
         self.assertEqual(out_lines[6], 'NT-TV/F-QGVAG---QSLQ')
Esempio n. 10
0
    def test_simple_docking_example(self):
        """Test simple-docking example"""
        with utils.temporary_directory() as tmpdir:
            subprocess.check_call([sys.executable,
                                   get_example_path("simple-docking.py")],
                                  cwd=tmpdir)

            # Make sure that a complete output file was produced
            with open(os.path.join(tmpdir, 'output.cif')) as fh:
                contents = fh.readlines()
            self.assertEqual(len(contents), 271)
Esempio n. 11
0
    def test_duplicate_datasets_details(self):
        """Datasets with differing details should be considered duplicates"""
        with utils.temporary_directory() as tmpdir:
            fname = os.path.join(tmpdir, 'test.pdb')
            _make_test_file(fname)
            l1 = ihm.location.InputFileLocation(fname, details='test details')
            d1 = ihm.dataset.PDBDataset(l1)

            l2 = ihm.location.InputFileLocation(fname, details='other details')
            d2 = ihm.dataset.PDBDataset(l2)
            self.assertEqual(l1, l2)
Esempio n. 12
0
    def test_duplicate_datasets_details(self):
        """Datasets with differing details should be considered duplicates"""
        with utils.temporary_directory() as tmpdir:
            fname = os.path.join(tmpdir, 'test.pdb')
            _make_test_file(fname)
            l1 = ihm.location.InputFileLocation(fname, details='test details')
            d1 = ihm.dataset.PDBDataset(l1)

            l2 = ihm.location.InputFileLocation(fname, details='other details')
            d2 = ihm.dataset.PDBDataset(l2)
            self.assertEqual(l1, l2)
Esempio n. 13
0
 def _read_cif(self, cif, real_file, category_handlers):
     if real_file:
         with utils.temporary_directory() as tmpdir:
             fname = os.path.join(tmpdir, 'test')
             with open(fname, 'w') as fh:
                 fh.write(cif)
             with open(fname) as fh:
                 r = ihm.format.CifReader(fh, category_handlers)
                 r.read_file()
     else:
         r = ihm.format.CifReader(StringIO(cif), category_handlers)
         r.read_file()
Esempio n. 14
0
 def _read_cif(self, cif, real_file, category_handlers):
     if real_file:
         with utils.temporary_directory() as tmpdir:
             fname = os.path.join(tmpdir, 'test')
             with open(fname, 'w') as fh:
                 fh.write(cif)
             with open(fname) as fh:
                 r = ihm.format.CifReader(fh, category_handlers)
                 r.read_file()
     else:
         r = ihm.format.CifReader(StringIO(cif), category_handlers)
         r.read_file()
Esempio n. 15
0
 def test_file_location_local(self):
     """Test InputFileLocation with a local file"""
     # Make tmpdir under current directory, as it's not always possible to
     # get a relative path from cwd to /tmp (e.g. on Windows where they may
     # be on different drives)
     with utils.temporary_directory('.') as tmpdir:
         fname = os.path.join(tmpdir, 'test.pdb')
         _make_test_file(fname)
         l = ihm.location.InputFileLocation(fname)
         self.assertEqual(l.path, os.path.abspath(fname))
         self.assertIsNone(l.repo)
         self.assertEqual(l.file_size, 8)
Esempio n. 16
0
 def test_file_location_local(self):
     """Test InputFileLocation with a local file"""
     # Make tmpdir under current directory, as it's not always possible to
     # get a relative path from cwd to /tmp (e.g. on Windows where they may
     # be on different drives)
     with utils.temporary_directory('.') as tmpdir:
         fname = os.path.join(tmpdir, 'test.pdb')
         _make_test_file(fname)
         l = ihm.location.InputFileLocation(fname)
         self.assertEqual(l.path, os.path.abspath(fname))
         self.assertEqual(l.repo, None)
         self.assertEqual(l.file_size, 8)
Esempio n. 17
0
    def test_simple_docking_example(self):
        """Test simple-docking example"""
        with utils.temporary_directory() as tmpdir:
            subprocess.check_call(
                [sys.executable,
                 get_example_path("simple-docking.py")],
                cwd=tmpdir)

            # Make sure that a complete output file was produced
            with open(os.path.join(tmpdir, 'output.cif')) as fh:
                contents = fh.readlines()
            self.assertEqual(len(contents), 271)
Esempio n. 18
0
 def _check_bad_cif(self, cif, real_file, category_handlers={}):
     """Ensure that the given bad cif results in a parser error"""
     if real_file:
         with utils.temporary_directory() as tmpdir:
             fname = os.path.join(tmpdir, 'test')
             with open(fname, 'w') as fh:
                 fh.write(cif)
             with open(fname) as fh:
                 r = ihm.format.CifReader(fh, category_handlers)
                 self.assertRaises(ihm.format.CifParserError, r.read_file)
     else:
         r = ihm.format.CifReader(StringIO(cif), category_handlers)
         self.assertRaises(ihm.format.CifParserError, r.read_file)
Esempio n. 19
0
 def test_simple(self):
     """Simple complete run of getavgpdb"""
     with utils.temporary_directory() as tmpdir:
         with open(os.path.join(tmpdir, 'align.ali'), 'w') as fh:
             fh.write(ALIGN_ALI)
         out = check_output(['allosmod', 'getavgpdb',
                            os.path.join(test_dir, 'input',
                                         'asite_pdb1.pdb'),
                            os.path.join(test_dir, 'input',
                                         'asite_pdb2.pdb'),
                            'pdb1', 'pdb2'], cwd=tmpdir)
         self.assertEqual(sorted(os.listdir(tmpdir)),
                          ['align.ali', 'avgpdb.pdb', 'list', 'run.log'])
Esempio n. 20
0
 def _check_bad_cif(self, cif, real_file, category_handlers={}):
     """Ensure that the given bad cif results in a parser error"""
     if real_file:
         with utils.temporary_directory() as tmpdir:
             fname = os.path.join(tmpdir, 'test')
             with open(fname, 'w') as fh:
                 fh.write(cif)
             with open(fname) as fh:
                 r = ihm.format.CifReader(fh, category_handlers)
                 self.assertRaises(ihm.format.CifParserError, r.read_file)
     else:
         r = ihm.format.CifReader(StringIO(cif), category_handlers)
         self.assertRaises(ihm.format.CifParserError, r.read_file)
    def test_opts(self):
        """Complete run of get_pm_initialstruct using different options"""
        from allosmod.get_pm_initialstruct import get_pm_initialstruct
        with utils.temporary_directory() as tmpdir:
            self.setup_inputs(tmpdir, seq='A/W')

            os.mkdir(os.path.join(tmpdir, 'pred_1fdx'))
            check_output(['allosmod', 'get_pm_initialstruct', '--target', 'foo',
                          '--restraints-only', 'test.aln', 'templates',
                          '.', '1', 'fast'], cwd=tmpdir)
            for f in ('1fdx', 'family.mat', 'foo.ini', 'test.aln',
                      'test.aln.ali', 'foo.rsr'):
                os.unlink(os.path.join(tmpdir, 'pred_1fdx', f))
Esempio n. 22
0
    def test_simple(self):
        """Simple test of pdb2ali"""
        with utils.temporary_directory() as tmpdir:
            with open(os.path.join(tmpdir, 'test.pdb'), 'w') as fh:
                fh.write(test_pdb)
            for out in (check_output(['allosmod', 'pdb2ali', 'test.pdb'],
                                     universal_newlines=True, cwd=tmpdir),
                        check_output(['python', '-m', 'allosmod.pdb2ali',
                                      'test.pdb'], universal_newlines=True,
                                      cwd=tmpdir)):
                self.assertEqual(out, """>P1;test.pdb
structureX:test.pdb:   1 :A:+12:B:::-1.00:-1.00
CMYh./CMY-frh.*
""")
    def test_nochdir(self):
        """Complete run of get_pm_initialstruct using --no-chdir"""
        from allosmod.get_pm_initialstruct import get_pm_initialstruct
        with utils.temporary_directory() as tmpdir:
            os.mkdir(os.path.join(tmpdir, 'pred_1fdx'))
            self.setup_inputs(tmpdir, seq='A/W', subdir='pred_1fdx')

            check_output(['allosmod', 'get_pm_initialstruct', '--target', 'foo',
                          '--restraints-only', '--no-chdir', '--csrfile',
                          'test.rsr', 'test.aln', '../templates', '.', '1',
                          'fast'], cwd=os.path.join(tmpdir, 'pred_1fdx'))
            for f in ('1fdx', 'family.mat', 'foo.ini', 'test.aln',
                      'test.aln.ali'):
                os.unlink(os.path.join(tmpdir, 'pred_1fdx', f))
Esempio n. 24
0
    def test_get_qioft(self):
        """Test get_qioft() function"""
        inputs = os.path.join(TOPDIR, 'test', 'input')
        with utils.temporary_directory() as tmpdir:
            subdir = os.path.join(tmpdir, 'XXX.pdb_14')
            os.mkdir(subdir)
            for f in ('list', 'pm.pdb.B10010001.pdb', 'pm_XXX.pdb'):
                shutil.copy(os.path.join(inputs, f), subdir)

            cryptosite.analysis.get_qioft(tmpdir)
            with open(os.path.join(subdir, 'qioft_pm_XXX.pdb_11sc.dat')) as fh:
                e = fh.readlines()
            self.assertEqual(e, ['0.2205 0.3422 0.5290 0.3791 0.2468 '
                         '0.4816 0.3841 0.5149 0.4896 0.0971 0.3187 0.0189 \n'])
Esempio n. 25
0
    def test_dcd_writer_framesize_mismatch(self):
        """Test DCDWriter class with framesize mismatch"""
        m1 = ihm.model.Model(None, None, None)
        m1._atoms = [ihm.model.Atom(None, None, None, None, x=1,y=2,z=3),
                     ihm.model.Atom(None, None, None, None, x=4,y=5,z=6)]
        m2 = ihm.model.Model(None, None, None)
        m2._atoms = [ihm.model.Atom(None, None, None, None, x=1,y=2,z=3)]

        with utils.temporary_directory() as tmpdir:
            dcd = os.path.join(tmpdir, 'out.dcd')

            with open(dcd, 'wb') as fh:
                d = ihm.model.DCDWriter(fh)
                d.add_model(m1)
                self.assertRaises(ValueError, d.add_model, m2)
Esempio n. 26
0
    def test_get_pdb_seq(self):
        """Test get_pdb_seq()"""
        with utils.temporary_directory() as tmpdir:
            fname = os.path.join(tmpdir, 'test.pdb')
            with open(fname, 'w') as fh:
                fh.write("""
ATOM      1  N   CYS A   1      18.511  -1.416  15.632  1.00  6.84           C
ATOM      2  C   CYS A   1      18.511  -1.416  15.632  1.00  6.84           C
ATOM      3  N   GLY A   2      18.511  -1.416  15.632  1.00  6.84           C
ATOM      4  C   GLY A   2      18.511  -1.416  15.632  1.00  6.84           C
ATOM      5  N   TYR B   3      18.511  -1.416  15.632  1.00  6.84           C
ATOM      6  C   TYR B   3      18.511  -1.416  15.632  1.00  6.84           C
""")
            seq = cleaning.get_pdb_seq(fname, 'A')
            self.assertEqual(seq, 'CG')
Esempio n. 27
0
    def test_get_pdb_seq(self):
        """Test get_pdb_seq()"""
        with utils.temporary_directory() as tmpdir:
            fname = os.path.join(tmpdir, 'test.pdb')
            with open(fname, 'w') as fh:
                fh.write("""
ATOM      1  N   CYS A   1      18.511  -1.416  15.632  1.00  6.84           C
ATOM      2  C   CYS A   1      18.511  -1.416  15.632  1.00  6.84           C
ATOM      3  N   GLY A   2      18.511  -1.416  15.632  1.00  6.84           C
ATOM      4  C   GLY A   2      18.511  -1.416  15.632  1.00  6.84           C
ATOM      5  N   TYR B   3      18.511  -1.416  15.632  1.00  6.84           C
ATOM      6  C   TYR B   3      18.511  -1.416  15.632  1.00  6.84           C
""")
            seq = cleaning.get_pdb_seq(fname, 'A')
            self.assertEqual(seq, 'CG')
Esempio n. 28
0
    def test_dcd_writer_framesize_mismatch(self):
        """Test DCDWriter class with framesize mismatch"""
        m1 = ihm.model.Model(None, None, None)
        m1._atoms = [ihm.model.Atom(None, None, None, None, x=1,y=2,z=3),
                     ihm.model.Atom(None, None, None, None, x=4,y=5,z=6)]
        m2 = ihm.model.Model(None, None, None)
        m2._atoms = [ihm.model.Atom(None, None, None, None, x=1,y=2,z=3)]

        with utils.temporary_directory() as tmpdir:
            dcd = os.path.join(tmpdir, 'out.dcd')

            with open(dcd, 'wb') as fh:
                d = ihm.model.DCDWriter(fh)
                d.add_model(m1)
                self.assertRaises(ValueError, d.add_model, m2)
Esempio n. 29
0
 def test_simple(self):
     """Simple test of getcofm"""
     with utils.temporary_directory() as tmpdir:
         with open(os.path.join(tmpdir, 'test.pdb'), 'w') as fh:
             fh.write(test_pdb)
         for out in (check_output(['allosmod', 'getcofm', 'test.pdb'],
                                  cwd=tmpdir),
                     check_output(['python', '-m', 'allosmod.getcofm',
                                   'test.pdb'], cwd=tmpdir)):
             x = float(out[:8])
             y = float(out[9:17])
             z = float(out[18:26])
             self.assertAlmostEqual(x, 2.214, places=3)
             self.assertAlmostEqual(y, 1.733, places=3)
             self.assertAlmostEqual(z, 1.067, places=3)
Esempio n. 30
0
    def test_get_qioft(self):
        """Test get_qioft() function"""
        inputs = os.path.join(TOPDIR, 'test', 'input')
        with utils.temporary_directory() as tmpdir:
            subdir = os.path.join(tmpdir, 'XXX.pdb_14')
            os.mkdir(subdir)
            for f in ('list', 'pm.pdb.B10010001.pdb', 'pm_XXX.pdb'):
                shutil.copy(os.path.join(inputs, f), subdir)

            cryptosite.analysis.get_qioft(tmpdir)
            with open(os.path.join(subdir, 'qioft_pm_XXX.pdb_11sc.dat')) as fh:
                e = fh.readlines()
            self.assertEqual(e, [
                '0.2205 0.3422 0.5290 0.3791 0.2468 '
                '0.4816 0.3841 0.5149 0.4896 0.0971 0.3187 0.0189 \n'
            ])
Esempio n. 31
0
    def test_rewrite_chain(self):
        """Make sure that pdb2ali rewrites empty chain IDs"""
        with utils.temporary_directory() as tmpdir:
            fname = os.path.join(tmpdir, 'test.pdb')
            with open(fname, 'w') as fh:
                fh.write(test_pdb.replace(' A ', '   '))
            out = check_output(['allosmod', 'pdb2ali', 'test.pdb'],
                               universal_newlines=True, cwd=tmpdir)
            self.assertEqual(out, """>P1;test.pdb
structureX:test.pdb:   1 :@:+12:B:::-1.00:-1.00
CMYh./CMY-frh.*
""")
            with open(fname) as fh:
                lines = fh.readlines()
            # Empty chain should have been reassigned as '@'
            self.assertEqual(lines[1][21], '@')
Esempio n. 32
0
    def test_rmf_em2d_restraint_provenance(self):
        """Test _RMFEM2DRestraintProvenance class"""
        rmf_node = MockRMFNode("r1", 1)

        with utils.temporary_directory() as tmpdir:
            pgm = os.path.join(tmpdir, 'test.pgm2')
            with open(pgm, 'w'):
                pass
            p = src.io._RMFEM2DRestraintProvenance(rmf_node, pgm, 4.0)
            self.assertEqual(
                p.name, 'EM class average from test.pgm2')
            mock_session = make_session()
            mock_session.logger = MockLogger()
            model = src.io._RMFModel(mock_session, 'fname')
            # Should be a noop since pgm2 isn't a known map format
            p.load(mock_session, model)
Esempio n. 33
0
    def test_wrap(self):
        """Make sure that long sequences from pdb2ali are wrapped"""
        with utils.temporary_directory() as tmpdir:
            with open(os.path.join(tmpdir, 'test.pdb'), 'w') as fh:
                for i in range(100):
                    fh.write("ATOM      1  N   CYS A   %-4d    1.453   "
                             "0.000   0.000  0.00  0.00           C\n" % (i+1))
                fh.write(test_pdb)
            out = check_output(['allosmod', 'pdb2ali', 'test.pdb'],
                               universal_newlines=True, cwd=tmpdir)
            self.assertEqual(out,
""">P1;test.pdb
structureX:test.pdb:   1 :A:+112:B:::-1.00:-1.00
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCCMYh./CMY-frh.*
""")
Esempio n. 34
0
 def test_cdensity_even_cutoff_positive(self):
     """Test contpres with even charge density, positive cutoff"""
     with utils.temporary_directory() as tmpdir:
         break_dat = os.path.join(tmpdir, 'break.dat')
         with open(break_dat, 'w') as fh:
             fh.write("foo\nbar\n")
         out = check_output(['allosmod', 'contpres', '--cdensity_cutoff',
                             '1.0', os.path.join(test_dir, 'input',
                                                 'contpres_evencd.rsr'),
                             os.path.join(test_dir, 'input',
                                          'contpres_evencd.pdb'), '50.0'],
                            cwd=tmpdir)
         with open(break_dat) as fh:
             content = fh.read()
         self.assertEqual(content, "foo\nbar\n")
         os.unlink(break_dat)
         os.unlink(os.path.join(tmpdir, 'contpres.dat'))
Esempio n. 35
0
    def test_detect_invalid_residue_types_bad(self):
        """Test _detect_invalid_residue_types() with bad sequence"""
        with utils.temporary_directory() as tmpdir:
            fname = os.path.join(tmpdir, 'test.pdb')
            with open(fname, 'w') as fh:
                fh.write("""
ATOM      1  N   CYS A   1      18.511  -1.416  15.632  1.00  6.84           C
ATOM      2  C   CYS A   1      18.511  -1.416  15.632  1.00  6.84           C
ATOM      3  N   HIE A   2      18.511  -1.416  15.632  1.00  6.84           C
ATOM      4  C   HIE A   2      18.511  -1.416  15.632  1.00  6.84           C
ATOM      5  N   HSD B   3      18.511  -1.416  15.632  1.00  6.84           C
ATOM      6  C   HSD B   3      18.511  -1.416  15.632  1.00  6.84           C
""")
            e = modeller.environ()
            m = modeller.model(e, file=fname)
        self.assertRaises(cleaning.InvalidResiduesError,
                          cleaning._detect_invalid_residue_types, m)
Esempio n. 36
0
 def test_cdensity(self):
     """Simple contpres in cdensity mode"""
     with utils.temporary_directory() as tmpdir:
         break_dat = os.path.join(tmpdir, 'break.dat')
         with open(break_dat, 'w') as fh:
             fh.write("foo\nbar\n")
         out = check_output(['allosmod', 'contpres', '--cdensity_cutoff',
                             '1.0', os.path.join(test_dir, 'input',
                                                 'test_contpres.rsr'),
                             os.path.join(test_dir, 'input',
                                          'test_contpres.pdb'), '50.0'],
                            cwd=tmpdir)
         with open(break_dat) as fh:
             content = fh.read()
         self.assertEqual(content, "foo\nbar\n2 50.0\n")
         os.unlink(break_dat)
         os.unlink(os.path.join(tmpdir, 'contpres.dat'))
Esempio n. 37
0
    def test_dcd_writer(self):
        """Test DCDWriter class"""
        m1 = ihm.model.Model(None, None, None)
        m1._atoms = [ihm.model.Atom(None, None, None, None, x=1,y=2,z=3),
                     ihm.model.Atom(None, None, None, None, x=4,y=5,z=6)]

        with utils.temporary_directory() as tmpdir:
            dcd = os.path.join(tmpdir, 'out.dcd')

            with open(dcd, 'wb') as fh:
                d = ihm.model.DCDWriter(fh)
                d.add_model(m1)
                d.add_model(m1)

            with open(dcd, 'rb') as fh:
                contents = fh.read()
        self.assertEqual(len(contents), 452)
Esempio n. 38
0
    def test_dcd_writer(self):
        """Test DCDWriter class"""
        m1 = ihm.model.Model(None, None, None)
        m1._atoms = [ihm.model.Atom(None, None, None, None, x=1,y=2,z=3),
                     ihm.model.Atom(None, None, None, None, x=4,y=5,z=6)]

        with utils.temporary_directory() as tmpdir:
            dcd = os.path.join(tmpdir, 'out.dcd')

            with open(dcd, 'wb') as fh:
                d = ihm.model.DCDWriter(fh)
                d.add_model(m1)
                d.add_model(m1)

            with open(dcd, 'rb') as fh:
                contents = fh.read()
        self.assertEqual(len(contents), 452)
Esempio n. 39
0
    def test_repository(self):
        """Test Repository"""
        # Make tmpdir under current directory, as it's not always possible to
        # get a relative path from cwd to /tmp (e.g. on Windows where they may
        # be on different drives)
        with utils.temporary_directory(os.getcwd()) as tmpdir:
            subdir = os.path.join(tmpdir, 'subdir')
            subdir2 = os.path.join(tmpdir, 'subdir2')
            os.mkdir(subdir)
            _make_test_file(os.path.join(subdir, 'bar'))
            s = ihm.location.Repository(doi='10.5281/zenodo.46266',
                                        root=os.path.relpath(tmpdir),
                                        url='foo',
                                        top_directory='baz')
            self.assertEqual(s._root, tmpdir)
            self.assertEqual(s.url, 'foo')
            self.assertEqual(s.top_directory, 'baz')

            loc = ihm.location.InputFileLocation(
                os.path.relpath(os.path.join(subdir, 'bar')))
            self.assertIsNone(loc.repo)
            ihm.location.Repository._update_in_repos(loc, [s])
            self.assertEqual(loc.repo.doi, '10.5281/zenodo.46266')
            self.assertEqual(loc.path, os.path.join('subdir', 'bar'))

            # Shouldn't touch locations that are already in repos
            loc = ihm.location.InputFileLocation(repo='foo', path='bar')
            self.assertEqual(loc.repo, 'foo')
            ihm.location.Repository._update_in_repos(loc, [s])
            self.assertEqual(loc.repo, 'foo')

            # Shortest match should win
            loc = ihm.location.InputFileLocation(
                os.path.relpath(os.path.join(subdir, 'bar')))
            s2 = ihm.location.Repository(doi='10.5281/zenodo.46280',
                                         root=os.path.relpath(subdir),
                                         url='foo',
                                         top_directory='baz')
            # Repositories that aren't above the file shouldn't count
            s3 = ihm.location.Repository(doi='10.5281/zenodo.56280',
                                         root=os.path.relpath(subdir2),
                                         url='foo',
                                         top_directory='baz')
            ihm.location.Repository._update_in_repos(loc, [s2, s3, s])
            self.assertEqual(loc.repo.doi, '10.5281/zenodo.46280')
            self.assertEqual(loc.path, 'bar')
Esempio n. 40
0
    def test_modify_patch_dock_params(self):
        """Test _modify_patch_dock_params() function"""
        with utils.temporary_directory() as tmpdir:
            fname = os.path.join(tmpdir, 'params.txt')
            with open(fname, 'w') as fh:
                fh.write("""
protLib /chem.lib
ligandSeg 5.0 15.0 0.1 1 1 1 5
clusterParams 0.05 2 1.0 2.0
""")
            cryptosite.patch_mapper._modify_patch_dock_params(fname)
            with open(fname) as fh:
                contents = fh.read()
        self.assertEqual(contents, """
protLib /chem.lib
ligandSeg 5.0 15.0 0.5 1 1 0 5
clusterParams 0.1 3 1.0 2.0
""")
    def test_simple(self):
        """Simple complete run of get_pm_initialstruct"""
        from allosmod.get_pm_initialstruct import get_pm_initialstruct
        with utils.temporary_directory() as tmpdir:
            self.setup_inputs(tmpdir)

            check_output(['allosmod', 'get_pm_initialstruct', '--target', 'foo',
                          '--keep-alignment', 'test.aln', 'templates',
                          '.', '1', 'slow'], cwd=tmpdir)
            e = modeller.environ()
            m = modeller.model(e, file=os.path.join(tmpdir, 'pred_1fdx',
                               'foo.B99990001.pdb'))
            self.assertEqual([x.code for x in m.residues], ['A', 'W'])
            self.assertEqual(m.chains[0].name, 'A')
            for f in ('1fdx', 'foo.B99990001.pdb', 'foo.ini', 'foo.sch',
                      'test.aln', 'foo.D00000001', 'foo.rsr',
                      'foo.V99990001'):
                os.unlink(os.path.join(tmpdir, 'pred_1fdx', f))
Esempio n. 42
0
 def test_simple(self):
     """Simple complete run of contpres"""
     with utils.temporary_directory() as tmpdir:
         break_dat = os.path.join(tmpdir, 'break.dat')
         with open(break_dat, 'w') as fh:
             fh.write("foo\nbar\n")
         out = check_output(['allosmod', 'contpres',
                             os.path.join(test_dir, 'input',
                                          'test_contpres.rsr'),
                             os.path.join(test_dir, 'input',
                                          'test_contpres.pdb'), '50.0'],
                            cwd=tmpdir)
         with open(break_dat) as fh:
             content = fh.read()
         self.assertEqual(content, "foo\nbar\n1 50.0\n3 50.0\n")
         with open(os.path.join(tmpdir, 'contpres.dat')) as fh:
             content = fh.read()
         self.assertEqual(content, "1 4\n2 0\n3 4\n")
Esempio n. 43
0
    def test_duplicate_locations(self):
        """Datasets with same location should be considered duplicates"""
        with utils.temporary_directory() as tmpdir:
            fname1 = os.path.join(tmpdir, 'test1.pdb')
            fname2 = os.path.join(tmpdir, 'test2.pdb')
            _make_test_file(fname1)
            _make_test_file(fname2)
            loc1 = ihm.location.InputFileLocation(fname1)
            loc2 = ihm.location.InputFileLocation(fname2)

            # Identical datasets in the same location aren't duplicated
            pdb1 = ihm.dataset.PDBDataset(loc1)
            pdb2 = ihm.dataset.PDBDataset(loc1)
            self.assertEqual(pdb1, pdb2)

            # Datasets in different locations are OK
            pdb1 = ihm.dataset.PDBDataset(loc1)
            pdb2 = ihm.dataset.PDBDataset(loc2)
            self.assertNotEqual(pdb1, pdb2)
Esempio n. 44
0
    def test_repository(self):
        """Test Repository"""
        # Make tmpdir under current directory, as it's not always possible to
        # get a relative path from cwd to /tmp (e.g. on Windows where they may
        # be on different drives)
        with utils.temporary_directory(os.getcwd()) as tmpdir:
            subdir = os.path.join(tmpdir, 'subdir')
            subdir2 = os.path.join(tmpdir, 'subdir2')
            os.mkdir(subdir)
            _make_test_file(os.path.join(subdir, 'bar'))
            s = ihm.location.Repository(doi='10.5281/zenodo.46266',
                                       root=os.path.relpath(tmpdir),
                                       url='foo', top_directory='baz')
            self.assertEqual(s._root, tmpdir)
            self.assertEqual(s.url, 'foo')
            self.assertEqual(s.top_directory, 'baz')

            loc = ihm.location.InputFileLocation(
                                 os.path.relpath(os.path.join(subdir, 'bar')))
            self.assertEqual(loc.repo, None)
            ihm.location.Repository._update_in_repos(loc, [s])
            self.assertEqual(loc.repo.doi, '10.5281/zenodo.46266')
            self.assertEqual(loc.path, os.path.join('subdir', 'bar'))

            # Shouldn't touch locations that are already in repos
            loc = ihm.location.InputFileLocation(repo='foo', path='bar')
            self.assertEqual(loc.repo, 'foo')
            ihm.location.Repository._update_in_repos(loc, [s])
            self.assertEqual(loc.repo, 'foo')

            # Shortest match should win
            loc = ihm.location.InputFileLocation(
                                os.path.relpath(os.path.join(subdir, 'bar')))
            s2 = ihm.location.Repository(doi='10.5281/zenodo.46280',
                                        root=os.path.relpath(subdir),
                                        url='foo', top_directory='baz')
            # Repositories that aren't above the file shouldn't count
            s3 = ihm.location.Repository(doi='10.5281/zenodo.56280',
                                        root=os.path.relpath(subdir2),
                                        url='foo', top_directory='baz')
            ihm.location.Repository._update_in_repos(loc, [s2, s3, s])
            self.assertEqual(loc.repo.doi, '10.5281/zenodo.46280')
            self.assertEqual(loc.path, 'bar')
Esempio n. 45
0
    def test_get_energy(self):
        """Test get_energy() function"""
        inputs = os.path.join(TOPDIR, 'test', 'input')
        with utils.temporary_directory() as tmpdir:
            subdir = os.path.join(tmpdir, 'XXX.pdb_14')
            os.mkdir(subdir)
            touch(os.path.join(subdir, 'pm.pdb.B10010001.pdb'))
            touch(os.path.join(subdir, 'pm.pdb.B10020001.pdb'))
            touch(os.path.join(subdir, 'pm.pdb.B99990001.pdb'))
            shutil.copy(os.path.join(inputs, 'pm.pdb.D00000001'), subdir)

            e = cryptosite.analysis.get_energy(tmpdir)
            with open(os.path.join(subdir, 'energy.dat')) as fh:
                e = fh.readlines()
            self.assertEqual(e,
                    ['   1000      13478.55371   0.0280   0.0836       '
                     '3374.72437        499.52283\n',
                     '   1000      13580.25098   0.0279   0.0794       '
                     '3332.75293        493.31027\n'])
Esempio n. 46
0
    def test_modify_patch_dock_params(self):
        """Test _modify_patch_dock_params() function"""
        with utils.temporary_directory() as tmpdir:
            fname = os.path.join(tmpdir, 'params.txt')
            with open(fname, 'w') as fh:
                fh.write("""
protLib /chem.lib
ligandSeg 5.0 15.0 0.1 1 1 1 5
clusterParams 0.05 2 1.0 2.0
""")
            cryptosite.patch_mapper._modify_patch_dock_params(fname)
            with open(fname) as fh:
                contents = fh.read()
        self.assertEqual(
            contents, """
protLib /chem.lib
ligandSeg 5.0 15.0 0.5 1 1 0 5
clusterParams 0.1 3 1.0 2.0
""")
Esempio n. 47
0
    def test_get_energy(self):
        """Test get_energy() function"""
        inputs = os.path.join(TOPDIR, 'test', 'input')
        with utils.temporary_directory() as tmpdir:
            subdir = os.path.join(tmpdir, 'XXX.pdb_14')
            os.mkdir(subdir)
            touch(os.path.join(subdir, 'pm.pdb.B10010001.pdb'))
            touch(os.path.join(subdir, 'pm.pdb.B10020001.pdb'))
            touch(os.path.join(subdir, 'pm.pdb.B99990001.pdb'))
            shutil.copy(os.path.join(inputs, 'pm.pdb.D00000001'), subdir)

            e = cryptosite.analysis.get_energy(tmpdir)
            with open(os.path.join(subdir, 'energy.dat')) as fh:
                e = fh.readlines()
            self.assertEqual(e, [
                '   1000      13478.55371   0.0280   0.0836       '
                '3374.72437        499.52283\n',
                '   1000      13580.25098   0.0279   0.0794       '
                '3332.75293        493.31027\n'
            ])
Esempio n. 48
0
    def test_first_data_block(self):
        """Only information from the first data block should be read"""
        cif = """
_foo.var1 test1
data_model
_foo.var2 test2
data_model2
_foo.var3 test3
"""
        h = GenericHandler()
        r = ihm.format.CifReader(StringIO(cif), {'_foo': h})
        self._check_first_data(r, h)

        with utils.temporary_directory() as tmpdir:
            fname = os.path.join(tmpdir, 'test')
            with open(fname, 'w') as fh:
                fh.write(cif)
            with open(fname) as fh:
                h = GenericHandler()
                r = ihm.format.CifReader(fh, {'_foo': h})
                self._check_first_data(r, h)
Esempio n. 49
0
    def test_rmf_em_restraint_provenance(self):
        """Test _RMFEMRestraintProvenance class"""
        rmf_node = MockRMFNode("r1", 1)

        # Test with non-existent GMM file
        p = src.io._RMFEMRestraintGMMProvenance(rmf_node, '/does/notexist')
        self.assertEqual(p.name, 'Gaussian Mixture Model from notexist')
        self.assertIsNone(p.previous)
        p.load(None, None)  # noop

        # Test with GMM file containing no metadata
        with utils.temporary_file(suffix='.gmm') as fname:
            with open(fname, 'w') as fh:
                pass
            p = src.io._RMFEMRestraintGMMProvenance(rmf_node, fname)
            self.assertIsNone(p.previous)

        # Test with GMM file containing valid metadata
        with utils.temporary_directory() as tmpdir:
            gmm = os.path.join(tmpdir, 'test.gmm')
            mrc = os.path.join(tmpdir, 'test.mrc2')
            with open(gmm, 'w') as fh:
                fh.write("""# Created by create_gmm.py
# data_fn: test.mrc2
# ncenters: 50
""")
            with open(mrc, 'w') as fh:
                pass
            p = src.io._RMFEMRestraintGMMProvenance(rmf_node, gmm)
            prev = p.previous
            self.assertEqual(prev.filename, mrc)
            self.assertEqual(p.name, 'Gaussian Mixture Model from test.gmm')
            self.assertEqual(prev.name, 'EM map from test.mrc2')
            mock_session = make_session()
            mock_session.logger = MockLogger()
            model = src.io._RMFModel(mock_session, 'fname')
            # Should be a noop since mrc2 isn't a known map format
            prev.load(mock_session, model)
Esempio n. 50
0
 def test_file_location_local_not_exist(self):
     """Test InputFileLocation with a local file that doesn't exist"""
     with utils.temporary_directory() as tmpdir:
         fname = os.path.join(tmpdir, 'test.pdb')
         self.assertRaises(ValueError, ihm.location.InputFileLocation,
                           fname)