def testLoadPDB(self): """ Check that we can load a pdb and convert it to a dict. """ # Setup path to pdb file. pdb_path = generateTestFilePath("2nip.pdb") self.__paths_to_remove.append('obsolete') # Attempt to load it. return_dict = IOUtilities.loadPDB(pdb_path) # Check items on dict. self.assertIsInstance( return_dict['Z'], numpy.ndarray ) self.assertIsInstance( return_dict['r'], numpy.ndarray ) self.assertIsInstance( return_dict['selZ'], dict ) self.assertIsInstance( return_dict['N'], int ) self.assertEqual( return_dict['Z'].shape, (4728,) ) self.assertEqual( return_dict['r'].shape, (4728,3) ) # Check that return type is a dict. self.assertIsInstance( return_dict, dict ) # Check exception on wrong input type. self.assertRaises( IOError, IOUtilities.loadPDB, [1,2] ) # Check exception on wrong file type. self.assertRaises( IOError, IOUtilities.loadPDB, generateTestFilePath("sample.h5") )
def testLoadPDB(self): """ Check that we can load a pdb and convert it to a dict. """ # Setup path to pdb file. pdb_path = generateTestFilePath("2nip.pdb") self.__paths_to_remove.append('obsolete') # Attempt to load it. return_dict = IOUtilities.loadPDB(pdb_path) # Check items on dict. self.assertIsInstance( return_dict['Z'], numpy.ndarray ) self.assertIsInstance( return_dict['r'], numpy.ndarray ) self.assertIsInstance( return_dict['selZ'], dict ) self.assertIsInstance( return_dict['N'], int ) self.assertEqual( return_dict['Z'].shape, (4728,) ) self.assertEqual( return_dict['r'].shape, (4728,3) ) # Check that return type is a dict. self.assertIsInstance( return_dict, dict ) # Check exception on corrupt file. # does not raise due to highly tolerant default acceptance levels in Bio.PDB. #self.assertRaises( IOError, IOUtilities.loadPDB, generateTestFilePath("2nip_corrupt.pdb" ) ) # Check exception on wrong input type. self.assertRaises( IOError, IOUtilities.loadPDB, [1,2] ) # Check exception on wrong file type. self.assertRaises( IOError, IOUtilities.loadPDB, generateTestFilePath("sample.h5") )
def notestQueryPDB(self): """ Check that we can query a non-existing pdb from pdb.org and convert it to a dict. """ # Setup path to pdb file. pdb_path = '2nip.pdb' self.__files_to_remove.append(pdb_path) self.__paths_to_remove.append('obsolete') # Attempt to load it. return_dict = IOUtilities.loadPDB(pdb_path) # Check items on dict. self.assertIsInstance( return_dict['Z'], numpy.ndarray ) self.assertIsInstance( return_dict['r'], numpy.ndarray ) self.assertIsInstance( return_dict['selZ'], dict ) self.assertIsInstance( return_dict['N'], int ) self.assertEqual( return_dict['Z'].shape, (4728,) ) self.assertEqual( return_dict['r'].shape, (4728,3) ) # Check that return type is a dict. self.assertIsInstance( return_dict, dict ) # Check exception on wrong input type. self.assertRaises( IOError, IOUtilities.loadPDB, 'xyz.pdb' )
def testQueryPDBDirectory(self): """ Check that if the pdb does not exist in the local database, it is queried from pdb.org, save in a dir, and convert it to a dict. """ # Setup path to pdb file. pdb_path = 'pdb/2nip.pdb' self.__files_to_remove.append(pdb_path) self.__paths_to_remove.append('obsolete') self.__paths_to_remove.append('pdb') os.mkdir('pdb') # Attempt to load it. return_dict = IOUtilities.loadPDB(pdb_path) # Check items on dict. self.assertIsInstance( return_dict['Z'], numpy.ndarray ) self.assertIsInstance( return_dict['r'], numpy.ndarray ) self.assertIsInstance( return_dict['selZ'], dict ) self.assertIsInstance( return_dict['N'], int ) self.assertEqual( return_dict['Z'].shape, (4728,) ) self.assertEqual( return_dict['r'].shape, (4728,3) ) # Check that return type is a dict. self.assertIsInstance( return_dict, dict )
def backengine(self): """ This method drives the backengine code.""" status = 0 input_files = [] if os.path.isfile(self.input_path): input_files = [self.input_path] elif os.path.isdir(self.input_path): input_files = [ os.path.join( self.input_path, f) for f in os.listdir( self.input_path ) if f.split('.')[-1] == 'h5' and f.split('.')[-2] != 'opmd' ] input_files.sort() else: raise IOError("Input file %s does not exist or cannot be read." % (self.input_path) ) # Create output directory if not existing yet. if not os.path.isdir( self.output_path ): os.mkdir( self.output_path ) elif os.path.isfile( self.output_path ): raise IOError( "Output file %s already exists, cowardly refusing to overwrite." % (self.output_path) ) # Generate formatted output files (i.e. attach history to output file). for i,input_file in enumerate(input_files): tail = input_file.split( 'prop' )[-1] output_file = os.path.join( self.output_path , 'pmi_out_%07d.h5' % (i+1) ) pmi_script.f_h5_out2in( input_file, output_file) # Get the backengine calculator. pmi_demo = PMIDemo() # Transfer some parameters. pmi_demo.g_s2e['prj'] = '' pmi_demo.g_s2e['id'] = tail.split('_')[-1].split('.')[0] pmi_demo.g_s2e['prop_out'] = input_file pmi_demo.g_s2e['setup'] = dict() pmi_demo.g_s2e['sys'] = dict() pmi_demo.g_s2e['setup']['num_digits'] = 7 if 'number_of_steps' in self.parameters.keys(): pmi_demo.g_s2e['steps'] = self.parameters['number_of_steps'] else: pmi_demo.g_s2e['steps'] = 100 pmi_demo.g_s2e['maxZ'] = 100 pmi_demo.g_s2e['setup']['pmi_out'] = output_file # Setup the database. pmi_demo.f_dbase_setup() # Go through the pmi workflow. pmi_demo.f_init_random() pmi_demo.f_save_info() pmi_demo.f_load_pulse( pmi_demo.g_s2e['prop_out'] ) # Check if sample is a h5 file. Horrible hack. try: h5 = h5py.File(self.__sample_path) h5.close() pmi_demo.f_load_sample(self.__sample_path) except: # Assume it's a pdb file. Will raise if not. atoms_dict = IOUtilities.loadPDB(self.__sample_path) pmi_demo.g_s2e['sample'] = atoms_dict pmi_demo.f_rotate_sample() pmi_demo.f_system_setup() # Perform the trajectories for this pulse and orientation. for traj in range( self.parameters['number_of_trajectories'] ): pmi_demo.f_time_evolution() return status