def setUp(self): """Create a temporary pipeline state in `self.state`.""" # Save dummy template to library. self.pdb_lib_dir = pathlib.Path(tempfile.mkdtemp()) template_file = (self.pdb_lib_dir / "xy" / "1xyz" / "1xyz_A.pdb") template_file.parent.mkdir(parents=True) template = self.template() with template_file.open("w") as template_out: template.write(template_out) # Create a temporary template database and add dummy template _, db_file = tempfile.mkstemp("-foldlib", "phyreengine-") self.template_db = pathlib.Path(db_file) TemplateDatabase.create(str(self.template_db)) template_db = TemplateDatabase( str(self.template_db), str(self.pdb_lib_dir)) template_db.add_pdb("1xyz", { "deposition_date": datetime.date(2000, 1, 1), "release_date": datetime.date(2000, 1, 1), "last_update_date": datetime.date(2000, 1, 1), "method": "X-RAY CRYSTALLOGRAPHY", }) template_db.add_template(template) template_db.commit() # Create empty directory for storing models and chdir there. self.model_dir = pathlib.Path(tempfile.mkdtemp()) self.orig_dir = os.getcwd() os.chdir(str(self.model_dir)) # Create pipeline state that can be modified without consequence. self.state = { "query_sequence": copy.deepcopy(self._QUERY_SEQ), "PDB": "1xyz", "chain": "A", "alignment": copy.deepcopy(self._ALIGNMENT), "rank": 1 } self.modeller = HomologyModeller( str(self.template_db), str(self.pdb_lib_dir)) self.results = self.modeller.run(self.state)
def test_add_retrieve_del_template(self): """Add PDB and template to database.""" template_db = TemplateDatabase(str(self.database), str(self.file_root)) template_db.add_pdb("12AS", self._METADATA) template_db.add_template(self.sample_template) template_db.commit() template = template_db.get_template("12AS", "A") self.assertEqual(template.canonical_seq, self.sample_template.canonical_seq) self.assertEqual(template.canonical_indices, self.sample_template.canonical_indices) self.assertEqual(template.mapping, self.sample_template.mapping) template_db.del_template("12as", "A") template_db.commit() with self.assertRaises(template_db.TemplateNotFoundException): template_db.get_template("12as", "A")