1 from __future__
import print_function
7 from optparse
import OptionParser
10 usage =
"""%prog [options] <data_fn> <n_components> <out_txt_fn>
11 Create a GMM from either density file (.mrc), a pdb file (.pdb)
12 Will detect input format from extension.
13 Outputs as text and optionally as a density map
16 parser = OptionParser(usage)
18 parser.add_option(
"-t",
"--covar_type",dest=
"covar_type",default=
'full',
19 choices=[
'spherical',
'tied',
'diag',
'full'],
20 help=
"covariance type for the GMM")
21 parser.add_option(
"-m",
"--out_map",dest=
"out_map",default=
'',
22 help=
"write out the gmm to an mrc file")
23 parser.add_option(
"-a",
"--apix",dest=
"apix",default=1.0,type=
'float',
24 help=
"if you don't provide a map, set the voxel_size here (for sampling)")
25 parser.add_option(
"-n",
"--num_samples",dest=
"num_samples",default=1000000,type=
'int',
26 help=
"num samples to draw from the density map")
27 parser.add_option(
"-i",
"--num_iter",dest=
"num_iter",default=100,type=
'int',
28 help=
"num iterations of GMM")
29 parser.add_option(
"-s",
"--threshold",dest=
"threshold",default=0.0,type=
'float',
30 help=
"threshold for the map before sampling")
32 parser.add_option(
"-c",
"--input_anchors_fn",dest=
"input_anchors_fn",default=
'',
33 help=
"get initial centers from anchors file. ")
34 parser.add_option(
"-f",
"--force_radii",dest=
"force_radii",default=-1.0,
36 help=
"force radii to be this value (spherical) -1 means deactivated ")
37 parser.add_option(
"-w",
"--force_weight",dest=
"force_weight",default=-1.0,
39 help=
"force weight to be this value (spherical) -1 means deactivated ")
40 parser.add_option(
"-e",
"--force_weight_frac",dest=
"force_weight_frac",action=
"store_true",default=
False,
41 help=
"force weight to be 1.0/(num anchors). takes precedence over -w ")
42 parser.add_option(
"-o",
"--out_anchors_txt",dest=
"out_anchors_txt",default=
'',
43 help=
"write final GMM as anchor points (txt)")
44 parser.add_option(
"-q",
"--out_anchors_cmm",dest=
"out_anchors_cmm",default=
'',
45 help=
"write final GMM as anchor points (cmm)")
46 parser.add_option(
"-d",
"--use_dirichlet",dest=
"use_dirichlet",default=
False,
48 help=
"use dirichlet process for fit")
50 parser.add_option(
"-k",
"--multiply_by_mass",dest=
"multiply_by_mass",default=
False,
52 help=
"if set, will multiply all weights by the total mass of the particles (PDB ONLY)")
53 parser.add_option(
"-x",
"--chain",dest=
"chain",default=
None,
54 help=
"If you passed a PDB file, read this chain")
56 parser.add_option(
"-z",
"--use_cpp",dest=
"use_cpp",default=
False,
58 help=
"EXPERIMENTAL. Uses the IMP GMM code. Requires isd_emxl")
61 (options, args) = parser.parse_args()
63 parser.error(
"incorrect number of arguments")
67 options,args = parse_args()
68 data_fn,ncenters,out_txt_fn = args
69 ncenters = int(ncenters)
72 if not os.path.isfile(data_fn):
73 raise Exception(
"The data file you entered: "+data_fn+
" does not exist!")
76 ext = data_fn.split(
'.')[-1]
85 if options.multiply_by_mass:
93 print(
'sampling points')
94 pts = IMP.isd.sample_points_from_density(dmap,options.num_samples,options.threshold)
96 print(
'ERROR: data_fn extension must be pdb, mrc, or npy')
100 if not options.use_cpp:
105 if options.force_weight_frac:
106 force_weight = 1.0/ncenters
108 force_weight=options.force_weight
109 if force_weight != -1:
110 print(
'weight forced to',force_weight)
111 if not options.use_dirichlet:
113 options.num_iter,options.covar_type,
114 force_radii=options.force_radii,
115 force_weight=options.force_weight,
116 mass_multiplier=mass_multiplier)
119 options.num_iter,options.covar_type,
120 mass_multiplier=mass_multiplier)
126 print(
"This option is experimental, only works if you have isd_emxl")
128 density_ps = IMP.isd_emxl.fit_gaussians_to_density(mdl,dmap,options.num_samples,
129 ncenters,options.num_iter,
135 if options.out_map!=
'':
140 if options.out_anchors_txt!=
'':
141 IMP.isd.gmm_tools.write_gmm_to_anchors(density_ps,options.out_anchors_txt,
142 options.out_anchors_cmm)
146 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.
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 ...