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([])
                        type=str,
                        required=True)

    args = parser.parse_args()

    if not os.path.isdir(args.pdb_dir):
        raise Exception("Invalid pdb directory location [%s]" % args.pdb_dir)

    if not os.path.isdir(os.path.dirname(args.output)):
        raise Exception("Output directory does not exists [%s]" %
                        os.path.dirname(args.output))

    if os.path.isfile(args.output):
        warnings.warn("output file will be overwritten [%s]" % args.output)

    amino = sd.get_amino(args.amino.upper())
    properties = args.properties if len(
        args.properties) > 0 else cg.CoarseGrainProperty.default_properties()

    logging.basicConfig(level=logging.DEBUG)
    logger = logging.getLogger('prepare_volume_feature_vectors')
    pdb_files = [
        os.path.join(args.pdb_dir, f) for f in os.listdir(args.pdb_dir)
        if f.endswith('.pdb')
    ]

    all_features = None
    for i, filename in enumerate(pdb_files):
        sig = get_signatures(filename,
                             amino,
                             property_list=properties,
import os
import regressor as reg
import coarse_graining as cg
import structural_dynamics as sd

if __name__ == "__main__":
    restype, chain_length = "ARG", 10
    model_file = os.path.join(os.path.dirname(__file__), 'data', 'arg_chain')
    pdb_file = os.path.join(os.path.dirname(__file__), 'data', 'structure.pdb')
    assert os.path.isdir(model_file) and os.path.isfile(pdb_file)
    ca_trace = sd.read_trajectory_catrace(pdb_file)[0]['B']
    model = reg.ChainedMLP(chain_length=chain_length, chained_incr=3)
    model.load(model_file)
    results = cg.place_atoms(ca_trace, model, sd.get_amino(restype))
    resids = sorted([int(k) for k in results.keys()])
    ca_coords = [ca_trace.xyz(r) for r in resids]
    entity, atom_id = [], 1
    for i, r in enumerate(resids):
        for atom, coords in results[r].items():
            entity.append({
                'resname': restype,
                'resid': r,
                'atomname': atom,
                'atomid': atom_id,
                'x': coords['x'],
                'y': coords['y'],
                'z': coords['z']
            })
            atom_id += 1
        entity.append({
            'resname': restype,
 def placement_vector(self, aa_type):
     aa = get_amino(aa_type).name(one_letter_code=False)
     if aa in self.__model_track:
         res_ids = sorted(self.__model_track[aa])
         return self.__residue_lookup.placement_vector(res_ids)
     return None
 def aligning_matrix(self, aa_type):
     aa = get_amino(aa_type).name(one_letter_code=False)
     if aa in self.__model_track:
         res_ids = sorted(self.__model_track[aa])
         return self.__residue_lookup.aligning_matrix(res_ids)
     return None
 def residue_ids(self, aa_type):
     aa = get_amino(aa_type).name(one_letter_code=False)
     if aa in self.__model_track:
         return sorted(self.__model_track[aa])
     return []