def get_signatures(pdbfile,
                   amino,
                   property_list,
                   nbrs):
    assert os.path.isfile(pdbfile)
    assert isinstance(property_list, list)
    assert nbrs > 2
    assert all([p in cg.CoarseGrainProperty.supported_properties() for p in property_list])
    pdblist = sd.read_pdb(pdbfile)
    assert len(pdblist) > 0
    chain = list(pdblist[0].keys())[0]
    pdb = pdblist[0][chain]
    sig = None
    logger = logging.getLogger('main.get_signatures')
    try:
        resids = pdb.find_residue(amino.name(one_letter_code=True))
        if len(resids) > 0:
            resids, sig, diheds = cg.get_model_dihedral_signature(pdb,
                                                                  resids,
                                                                  properties=property_list,
                                                                  topn=nbrs)
            assert len(sig) == len(diheds)
            sig = np.concatenate([np.array(sig, dtype=np.float), np.array(diheds, dtype=np.float)], axis=1)
    except:
        logger.warning('Failed to process file [%s]' % pdbfile)
    return sig
def get_signatures(pdbfile, amino, property_list, nbrs):
    assert os.path.isfile(pdbfile)
    assert isinstance(property_list, list)
    assert nbrs > 2
    assert all([
        p in cg.CoarseGrainProperty.supported_properties()
        for p in property_list
    ])
    pdblist = sd.read_pdb(pdbfile)
    assert len(pdblist) > 0
    chain = list(pdblist[0].keys())[0]
    pdb = pdblist[0][chain]
    try:
        ca_trace = sd.pdb_to_catrace(pdb)
    except:
        return np.array([])
    assert isinstance(pdb, sd.PDBStructure)
    residue_ids = [r for r in pdb.residue_ids if r > 0][1:-1]
    residue_ids = [
        r for r in residue_ids if sd.get_amino(pdb.residue_name(r)) == amino
    ]
    residue_ids = cg.filter_complete_residues(pdb, residue_ids)
    vol = cg.Volume3D(size=cg.VolumeSignatureGrid.size(),
                      dim=cg.VolumeSignatureGrid.dim())
    if len(residue_ids) > 0:
        vol_signature = []
        for r in residue_ids:
            vol_signature.append(vol.get_signature(pdb, r, reset=True))
        nbr_signature = cg.cg_neighbor_signature(ca_trace,
                                                 residues=residue_ids,
                                                 properties=property_list,
                                                 topn=nbrs)
        vol_signature, nbr_signature = np.array(vol_signature), np.array(
            nbr_signature)
        if vol_signature.shape[0] == nbr_signature.shape[0]:
            return np.concatenate((nbr_signature, vol_signature), axis=1)
    return np.array([])
def get_signatures(pdbfile, amino, property_list, nbrs):
    assert os.path.isfile(pdbfile)
    assert isinstance(property_list, list)
    assert nbrs > 2
    assert all([
        p in cg.CoarseGrainProperty.supported_properties()
        for p in property_list
    ])
    pdblist = sd.read_pdb(pdbfile)
    assert len(pdblist) > 0
    chain = list(pdblist[0].keys())[0]
    pdb = pdblist[0][chain]
    logger = logging.getLogger('main.get_signatures')
    try:
        sig = cg.get_atom_position_signature(pdb,
                                             amino,
                                             properties=property_list,
                                             topn=nbrs)
        for aa in sig.keys():
            sig[aa] = np.array(sig[aa], dtype=np.float)
    except:
        logger.warning('Failed to process file [%s]' % pdbfile)
        sig = {}
    return sig
Ejemplo n.º 4
0
                        default=4,
                        help="Number of neighboring residues (default: 4)")

    parser.add_argument("--out",
                        action='store',
                        dest='out_pml',
                        type=str,
                        required=True,
                        help="Out file location")

    args = parser.parse_args()

    if not os.path.isfile(args.pdb_file):
        raise Exception("Can not read pdb file [%s]" % args.pdb_file)

    pdb_list = sd.read_pdb(args.pdb_file)
    chain = args.chain

    assert len(pdb_list) == 1
    neigbors = []
    r_0, r_1, r_2 = args.residue - 1, args.residue, args.residue + 1

    for pdbs in pdb_list:
        assert isinstance(pdbs, dict)
        assert chain in pdbs
        ca_trace = sd.pdb_to_catrace(pdbs[chain])
        valid_residues = ca_trace.residue_ids[1:-1]
        if args.residue not in valid_residues:
            raise Exception("Residue %d not a valid residue!" % args.residue)
        neighbors = cg.find_k_neighbors(pdb=ca_trace,
                                        residues=[args.residue],
Ejemplo n.º 5
0
    trajectory = sd.read_trajectory_catrace(args.trajectory)
    assert len(trajectory) > 0

    max_coordinate, min_coordinate = read_bounding_box(args.bb_file)
    for i in range(len(max_coordinate)):
        max_coordinate[i] += args.buffer
        min_coordinate[i] -= args.buffer

    trajectory = [snap[args.chain] for snap in trajectory]

    align_map = None
    if args.align_map is not None:
        align_map = parse_alignment(args.align_map)

    if args.ref_pdb is not None:
        ref_pdb = sd.read_pdb(args.ref_pdb)
        assert (len(ref_pdb) == 1) and (len(ref_pdb[0]) == 1)
        chain = list(ref_pdb[0].keys())[0]
        ref_pdb = sd.pdb_to_catrace(ref_pdb[0][chain])
        trajectory = mm.align_trajectory(ref_structure=ref_pdb,
                                         tgt_structure=trajectory[0],
                                         trajectory=trajectory,
                                         align_pair=align_map,
                                         ca_trace=True)

    signature = mm.Signature(max_coord=max_coordinate,
                             min_coord=min_coordinate)

    res_names = dict()
    for trace in trajectory:
        for res_id in trace.residue_ids:
Ejemplo n.º 6
0
import os
import time
from mutant_model import *
from structural_dynamics import read_trajectory_catrace, read_pdb, pdb_to_catrace

if __name__ == "__main__":
    pdb_file = os.path.join(os.path.dirname(__file__), 'data',
                            'structure_1a1v.pdb')
    trj_file2 = os.path.join(os.path.dirname(__file__), 'data',
                             'ex_trajectory_2.pdb')
    assert os.path.isfile(pdb_file) and os.path.isfile(trj_file2)
    ref_pdb = pdb_to_catrace(read_pdb(pdb_file)[0]['A'])
    trj = [pair['A'] for pair in read_trajectory_catrace(trj_file2)]
    start = time.time()
    aln_trj = align_trajectory(ref_pdb, trj[0], trj, ca_trace=True)
    end = time.time()
    print("Alignment time: %f" % (end - start))
    out_file = os.path.join(os.path.dirname(__file__), 'out',
                            'aligned_to_1a1v.pdb')
    with open(out_file, "w") as fh:
        for i, snapshot in enumerate(aln_trj):
            fh.write("MODEL %6d\n" % (i + 1))
            snapshot.write(fh)
            fh.write("ENDMDL\n")