1 from __future__
import print_function
6 from IMP
import ArgumentParser
12 Create a GMM from either density file (.mrc), a pdb file (.pdb)
13 Will detect input format from extension.
14 Outputs as text and optionally as a density map
17 p = ArgumentParser(description=desc)
19 p.add_argument(
"-t",
"--covar_type",dest=
"covar_type",default=
'full',
20 choices=[
'spherical',
'tied',
'diag',
'full'],
21 help=
"covariance type for the GMM")
22 p.add_argument(
"-m",
"--out_map",dest=
"out_map",default=
'',
23 help=
"write out the gmm to an mrc file")
24 p.add_argument(
"-a",
"--apix",dest=
"apix",default=1.0,type=float,
25 help=
"if you don't provide a map, set the voxel_size here (for sampling)")
26 p.add_argument(
"-n",
"--num_samples",dest=
"num_samples",default=1000000,type=int,
27 help=
"num samples to draw from the density map")
28 p.add_argument(
"-i",
"--num_iter",dest=
"num_iter",default=100,type=int,
29 help=
"num iterations of GMM")
30 p.add_argument(
"-s",
"--threshold",dest=
"threshold",default=0.0,type=float,
31 help=
"threshold for the map before sampling")
33 p.add_argument(
"-f",
"--force_radii",dest=
"force_radii",default=-1.0,
35 help=
"force radii to be this value (spherical) -1 means deactivated ")
36 p.add_argument(
"-w",
"--force_weight",dest=
"force_weight",default=-1.0,
38 help=
"force weight to be this value (spherical) -1 means deactivated ")
39 p.add_argument(
"-e",
"--force_weight_frac", dest=
"force_weight_frac",
40 action=
"store_true", default=
False,
41 help=
"force weight to be 1.0/(num centers). "
42 "Takes precedence over -w")
43 p.add_argument(
"-d",
"--use_dirichlet",dest=
"use_dirichlet",default=
False,
45 help=
"use dirichlet process for fit")
47 p.add_argument(
"-k",
"--multiply_by_mass",dest=
"multiply_by_mass",default=
False,
49 help=
"if set, will multiply all weights by the total mass of the particles (PDB ONLY)")
50 p.add_argument(
"-x",
"--chain",dest=
"chain",default=
None,
51 help=
"If you passed a PDB file, read this chain")
53 p.add_argument(
"-z",
"--use_cpp",dest=
"use_cpp",default=
False,
55 help=
"EXPERIMENTAL. Uses the IMP GMM code. Requires isd_emxl")
56 p.add_argument(
"data_file", help=
"data file name")
57 p.add_argument(
"n_centers", type=int, help=
"number of centers")
58 p.add_argument(
"out_file", help=
"output file name")
62 data_fn = args.data_file
63 ncenters = args.n_centers
64 out_txt_fn = args.out_file
67 if not os.path.isfile(data_fn):
68 raise Exception(
"The data file you entered: "+data_fn+
" does not exist!")
71 ext = data_fn.split(
'.')[-1]
80 if args.multiply_by_mass:
88 dmap.set_was_used(
True)
89 print(
'sampling points')
90 pts = IMP.isd.sample_points_from_density(dmap,args.num_samples,args.threshold)
92 raise ValueError(
"data_fn extension must be pdb or mrc")
100 if args.force_weight_frac:
101 force_weight = 1.0/ncenters
103 force_weight=args.force_weight
104 if force_weight != -1:
105 print(
'weight forced to',force_weight)
106 if not args.use_dirichlet:
108 args.num_iter,args.covar_type,
109 force_radii=args.force_radii,
110 force_weight=args.force_weight,
111 mass_multiplier=mass_multiplier)
114 args.num_iter,args.covar_type,
115 mass_multiplier=mass_multiplier)
121 print(
"This option is experimental, only works if you have isd_emxl")
123 density_ps = IMP.isd_emxl.fit_gaussians_to_density(mdl,dmap,args.num_samples,
124 ncenters,args.num_iter,
129 comments = [
'Created by create_gmm.py, IMP.isd version %s'
132 comments.append(
'ncenters: %d' % ncenters)
133 for key
in (
'covar_type',
'apix',
'num_samples',
'num_iter',
134 'threshold',
'force_radii',
'force_weight',
135 'force_weight_frac',
'use_dirichlet',
'multiply_by_mass',
137 comments.append(
'%s: %s' % (key, repr(getattr(args, key))))
139 if args.out_map !=
'':
147 if __name__==
"__main__":
Select non water and non hydrogen atoms.
double get_mass(ResidueType c)
Get the mass from the residue type.
GenericHierarchies get_leaves(Hierarchy mhd)
Get all the leaves of the bit of hierarchy.
void read_pdb(TextInput input, int model, Hierarchy h)
Class for storing model, its restraints, constraints, and particles.
std::string get_module_version()
std::string get_relative_path(std::string base, std::string relative)
Return a path to a file relative to another file.
Basic utilities for handling cryo-electron microscopy 3D density maps.
A decorator for a particle with x,y,z coordinates.
algebra::BoundingBoxD< 3 > get_bounding_box(const DensityMap *m)
Select hierarchy particles identified by the biological name.
Inferential scoring building on methods developed as part of the Inferential Structure Determination ...