Source code for kvazar.fileman

# -*- coding: utf-8 -*-
import os
import shutil
import numpy
from core.structure import Structure

from futils import parse_acd, parse_pdb#, parse_out
from futils import save_acd#, save_pdb, save_out

class FileManagerException(Exception):
    def __init__(self, message):
        super(FileManagerException, self).__init__(message)

[docs]class FileManager(object): """ It's a class for structure loading from files. Possible extensions of files for loading are ACD, ACC, PDB. Now there is only one possible extension for saving: ACD. Also class checks existance of direcory and makes the new one, if needed. Raise exception in the case of unknown extension. """ def __init__(self): self.struct = None def ensure_dir(self, d): if not os.path.exists(d): os.makedirs(d) def delete_dir(self, d): if os.path.exists(d): shutil.rmtree(d) def set_struct(self, struct): self.struct = struct def get_struct(self): return self.struct def load(self, filename): _, file_ext = os.path.splitext(filename) file_ext = file_ext.lower() if file_ext == '.acd': self.struct = Structure(parse_acd(filename)) elif file_ext == '.pdb': self.struct = Structure(parse_pdb(filename)) elif file_ext == '.out': self.struct = parse_out(filename) else: raise FileManagerException("Unknown file extension .%s" % file_ext) return self.struct def save(self, filename): _, file_ext = os.path.splitext(filename) file_ext = file_ext.lower() if file_ext == '.acd': save_acd(self.struct, filename) else: raise FileManagerException('Unknown file extension .%s' % file_ext)