def retrieve(pdb_id, cache_dir = None): '''Creates a PDBML object by using a cached copy of the files if they exists or by retrieving the files from the RCSB.''' pdb_contents = None xml_contents = None pdb_id = pdb_id.upper() if cache_dir: # Check to see whether we have a cached copy of the PDB file filename = os.path.join(cache_dir, "%s.pdb" % pdb_id) if os.path.exists(filename): pdb_contents = read_file(filename) # Check to see whether we have a cached copy of the XML file filename = os.path.join(cache_dir, "%s.xml" % pdb_id) if os.path.exists(filename): xml_contents = read_file(filename) # Get any missing files from the RCSB and create cached copies if appropriate if not pdb_contents: pdb_contents = rcsb.retrieve_pdb(pdb_id) if cache_dir: write_file(os.path.join(cache_dir, "%s.pdb" % pdb_id), pdb_contents) if not xml_contents: xml_contents = rcsb.retrieve_xml(pdb_id) if cache_dir: write_file(os.path.join(cache_dir, "%s.xml" % pdb_id), xml_contents) # Return the object return PDBML_slow(xml_contents, pdb_contents)
def retrieve(cls, pdb_id, cache_dir = None): '''Creates a PDB object by using a cached copy of the file if it exists or by retrieving the file from the RCSB.''' # Check to see whether we have a cached copy pdb_id = pdb_id.upper() if cache_dir: filename = os.path.join(cache_dir, "%s.pdb" % pdb_id) if os.path.exists(filename): return cls(read_file(filename)) # Get a copy from the RCSB contents = rcsb.retrieve_pdb(pdb_id) # Create a cached copy if appropriate if cache_dir: write_file(os.path.join(cache_dir, "%s.pdb" % pdb_id), contents) # Return the object return cls(contents)