Example #1
0
def run_naccess(model, pdb_file, probe_size=None, z_slice=None, naccess="naccess", temp_path="/tmp/"):

    # make temp directory;
    tmp_path = tempfile.mkdtemp(dir=temp_path)

    # file name must end with '.pdb' to work with NACCESS
    # -> create temp file of existing pdb
    #    or write model to temp file
    handle, tmp_pdb_file = tempfile.mkstemp(".pdb", dir=tmp_path)
    os.close(handle)
    if pdb_file:
        pdb_file = os.path.abspath(pdb_file)
        shutil.copy(pdb_file, tmp_pdb_file)
    else:
        writer = PDBIO()
        writer.set_structure(model.get_parent())
        writer.save(tmp_pdb_file)

    # chdir to temp directory, as NACCESS writes to current working directory
    old_dir = os.getcwd()
    os.chdir(tmp_path)

    # create the command line and run
    # catch standard out & err
    command = [naccess, tmp_pdb_file]
    if probe_size:
        command.extend(["-p", probe_size])
    if z_slice:
        command.extend(["-z", z_slice])

    p = subprocess.Popen(command, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = p.communicate()
    os.chdir(old_dir)

    # get the output, then delete the temp directory
    rsa_file = tmp_pdb_file[:-4] + ".rsa"
    with open(rsa_file) as rf:
        rsa_data = rf.readlines()
    asa_file = tmp_pdb_file[:-4] + ".asa"
    with open(asa_file) as af:
        asa_data = af.readlines()

    shutil.rmtree(tmp_path, ignore_errors=True)
    return rsa_data, asa_data
Example #2
0
File: Dice.py Project: cbirdlab/sap
def extract(structure, chain_id, start, end, filename):
    """
    Write out selected portion to filename.
    """
    sel=ChainSelector(chain_id, start, end)
    io=PDBIO()
    io.set_structure(structure)
    io.save(filename, sel)
Example #3
0
def run_naccess(model,
                pdb_file,
                probe_size=None,
                z_slice=None,
                naccess='naccess',
                temp_path='/tmp/'):

    # make temp directory;
    tmp_path = tempfile.mkdtemp(dir=temp_path)

    # file name must end with '.pdb' to work with NACCESS
    # -> create temp file of existing pdb
    #    or write model to temp file
    handle, tmp_pdb_file = tempfile.mkstemp('.pdb', dir=tmp_path)
    os.close(handle)
    if pdb_file:
        pdb_file = os.path.abspath(pdb_file)
        shutil.copy(pdb_file, tmp_pdb_file)
    else:
        writer = PDBIO()
        writer.set_structure(model.get_parent())
        writer.save(tmp_pdb_file)

    # chdir to temp directory, as NACCESS writes to current working directory
    old_dir = os.getcwd()
    os.chdir(tmp_path)

    # create the command line and run
    # catch standard out & err
    command = [naccess, tmp_pdb_file]
    if probe_size:
        command.extend(['-p', probe_size])
    if z_slice:
        command.extend(['-z', z_slice])

    p = subprocess.Popen(command,
                         universal_newlines=True,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE)
    out, err = p.communicate()
    os.chdir(old_dir)

    # get the output, then delete the temp directory
    rsa_file = tmp_pdb_file[:-4] + '.rsa'
    with open(rsa_file) as rf:
        rsa_data = rf.readlines()
    asa_file = tmp_pdb_file[:-4] + '.asa'
    with open(asa_file) as af:
        asa_data = af.readlines()

    shutil.rmtree(tmp_path, ignore_errors=True)
    return rsa_data, asa_data