1 """@namespace IMP.pmi.output
2 Classes for writing output files and processing them.
14 import cPickle
as pickle
19 """Class for easy writing of PDBs, RMFs, and stat files"""
20 def __init__(self, ascii=True,atomistic=False):
21 self.dictionary_pdbs = {}
22 self.dictionary_rmfs = {}
23 self.dictionary_stats = {}
24 self.dictionary_stats2 = {}
25 self.best_score_list =
None
26 self.nbestscoring =
None
28 self.replica_exchange =
False
32 self.chainids =
"ABCDEFGHIJKLMNOPQRSTUVXYWZabcdefghijklmnopqrstuvxywz"
34 self.particle_infos_for_pdb = {}
35 self.atomistic=atomistic
37 def get_pdb_names(self):
38 return self.dictionary_pdbs.keys()
40 def get_rmf_names(self):
41 return self.dictionary_rmfs.keys()
43 def get_stat_names(self):
44 return self.dictionary_stats.keys()
46 def init_pdb(self, name, prot):
47 flpdb = open(name,
'w')
49 self.dictionary_pdbs[name] = prot
50 self.dictchain[name] = {}
52 for n, i
in enumerate(self.dictionary_pdbs[name].get_children()):
53 self.dictchain[name][i.get_name()] = self.chainids[n]
56 translate_to_geometric_center=
False):
59 flpdb = open(name,
'a')
61 flpdb = open(name,
'w')
63 (particle_infos_for_pdb,
64 geometric_center) = self.get_particle_infos_for_pdb_writing(name)
66 if not translate_to_geometric_center:
67 geometric_center = (0, 0, 0)
69 for tupl
in particle_infos_for_pdb:
71 (xyz, atom_index, atom_type, residue_type,
72 chain_id, residue_index,radius) = tupl
74 flpdb.write(IMP.atom.get_pdb_string((xyz[0] - geometric_center[0],
75 xyz[1] - geometric_center[1],
76 xyz[2] - geometric_center[2]),
77 atom_index, atom_type, residue_type,
78 chain_id, residue_index,
' ',1.00,radius))
80 flpdb.write(
"ENDMOL\n")
83 del particle_infos_for_pdb
85 def get_particle_infos_for_pdb_writing(self, name):
95 particle_infos_for_pdb = []
97 geometric_center = [0, 0, 0]
107 p, self.dictchain[name])
109 if protname
not in resindexes_dict:
110 resindexes_dict[protname] = []
115 rt = residue.get_residue_type()
116 resind = residue.get_index()
120 geometric_center[0] += xyz[0]
121 geometric_center[1] += xyz[1]
122 geometric_center[2] += xyz[2]
124 particle_infos_for_pdb.append((xyz, atom_index,
125 atomtype, rt, self.dictchain[name][protname], resind,radius))
126 resindexes_dict[protname].append(resind)
131 resind = residue.get_index()
134 if resind
in resindexes_dict[protname]:
137 resindexes_dict[protname].append(resind)
139 rt = residue.get_residue_type()
142 geometric_center[0] += xyz[0]
143 geometric_center[1] += xyz[1]
144 geometric_center[2] += xyz[2]
146 particle_infos_for_pdb.append((xyz, atom_index,
147 IMP.atom.AT_CA, rt, self.dictchain[name][protname], resind,radius))
156 resind = resindexes[len(resindexes) / 2]
157 if resind
in resindexes_dict[protname]:
160 resindexes_dict[protname].append(resind)
165 geometric_center[0] += xyz[0]
166 geometric_center[1] += xyz[1]
167 geometric_center[2] += xyz[2]
169 particle_infos_for_pdb.append((xyz, atom_index,
170 IMP.atom.AT_CA, rt, self.dictchain[name][protname], resind,radius))
177 resind = resindexes[len(resindexes) / 2]
180 geometric_center[0] += xyz[0]
181 geometric_center[1] += xyz[1]
182 geometric_center[2] += xyz[2]
184 particle_infos_for_pdb.append((xyz, atom_index,
185 IMP.atom.AT_CA, rt, self.dictchain[name][protname], resind,radius))
191 geometric_center = (geometric_center[0] / atom_count,
192 geometric_center[1] / atom_count,
193 geometric_center[2] / atom_count)
195 return (particle_infos_for_pdb, geometric_center)
197 #now write the connectivity
198 for protname in index_residue_pair_list:
200 ls=index_residue_pair_list[protname]
202 ls=sorted(ls, key=lambda tup: tup[1])
204 indexes=map(list, zip(*ls))[0]
205 # get the contiguous pairs
206 indexes_pairs=list(IMP.pmi.tools.sublist_iterator(indexes,lmin=2,lmax=2))
207 #write the connection record only if the residue gap is larger than 1
209 for ip in indexes_pairs:
210 if abs(ip[1]-ip[0])>1:
211 flpdb.write('{:6s}{:5d}{:5d}'.format('CONECT',ip[0],ip[1]))
215 def write_pdbs(self, appendmode=True):
216 for pdb
in self.dictionary_pdbs.keys():
217 self.write_pdb(pdb, appendmode)
219 def init_pdb_best_scoring(
224 replica_exchange=
False):
228 self.suffixes.append(suffix)
229 self.replica_exchange = replica_exchange
230 if not self.replica_exchange:
234 self.best_score_list = []
238 self.best_score_file_name =
"best.scores.rex.py"
239 self.best_score_list = []
240 best_score_file = open(self.best_score_file_name,
"w")
241 best_score_file.write(
242 "self.best_score_list=" + str(self.best_score_list))
243 best_score_file.close()
245 self.nbestscoring = nbestscoring
246 for i
in range(self.nbestscoring):
247 name = suffix +
"." + str(i) +
".pdb"
248 flpdb = open(name,
'w')
250 self.dictionary_pdbs[name] = prot
251 self.dictchain[name] = {}
252 for n, i
in enumerate(self.dictionary_pdbs[name].get_children()):
253 self.dictchain[name][i.get_name()] = self.chainids[n]
255 def write_pdb_best_scoring(self, score):
256 if self.nbestscoring
is None:
257 print "Output.write_pdb_best_scoring: init_pdb_best_scoring not run"
260 if self.replica_exchange:
262 execfile(self.best_score_file_name)
264 if len(self.best_score_list) < self.nbestscoring:
265 self.best_score_list.append(score)
266 self.best_score_list.sort()
267 index = self.best_score_list.index(score)
268 for suffix
in self.suffixes:
269 for i
in range(len(self.best_score_list) - 2, index - 1, -1):
270 oldname = suffix +
"." + str(i) +
".pdb"
271 newname = suffix +
"." + str(i + 1) +
".pdb"
272 os.rename(oldname, newname)
273 filetoadd = suffix +
"." + str(index) +
".pdb"
274 self.write_pdb(filetoadd, appendmode=
False)
277 if score < self.best_score_list[-1]:
278 self.best_score_list.append(score)
279 self.best_score_list.sort()
280 self.best_score_list.pop(-1)
281 index = self.best_score_list.index(score)
282 for suffix
in self.suffixes:
283 for i
in range(len(self.best_score_list) - 1, index - 1, -1):
284 oldname = suffix +
"." + str(i) +
".pdb"
285 newname = suffix +
"." + str(i + 1) +
".pdb"
286 os.rename(oldname, newname)
287 filenametoremove = suffix + \
288 "." + str(self.nbestscoring) +
".pdb"
289 os.remove(filenametoremove)
290 filetoadd = suffix +
"." + str(index) +
".pdb"
291 self.write_pdb(filetoadd, appendmode=
False)
293 if self.replica_exchange:
295 best_score_file = open(self.best_score_file_name,
"w")
296 best_score_file.write(
297 "self.best_score_list=" + str(self.best_score_list))
298 best_score_file.close()
300 def init_rmf(self, name, hierarchies,rs=None):
301 rh = RMF.create_rmf_file(name)
305 self.dictionary_rmfs[name] = rh
307 def add_restraints_to_rmf(self, name, objectlist):
310 rs = o.get_restraint_for_rmf()
312 rs = o.get_restraint()
314 self.dictionary_rmfs[name],
317 def add_geometries_to_rmf(self, name, objectlist):
319 geos = o.get_geometries()
322 def add_particle_pair_from_restraints_to_rmf(self, name, objectlist):
325 pps = o.get_particle_pairs()
327 IMP.rmf.add_geometry(
328 self.dictionary_rmfs[name],
331 def write_rmf(self, name):
333 self.dictionary_rmfs[name].flush()
335 def close_rmf(self, name):
336 del self.dictionary_rmfs[name]
338 def write_rmfs(self):
339 for rmf
in self.dictionary_rmfs.keys():
342 def init_stat(self, name, listofobjects):
344 flstat = open(name,
'w')
347 flstat = open(name,
'wb')
351 for l
in listofobjects:
352 if not "get_output" in dir(l):
353 print "Output: object", l,
"doesn't have get_output() method"
355 self.dictionary_stats[name] = listofobjects
357 def set_output_entry(self, key, value):
358 self.initoutput.update({key: value})
360 def write_stat(self, name, appendmode=True):
361 output = self.initoutput
362 for obj
in self.dictionary_stats[name]:
365 dfiltered = dict((k, v)
for k, v
in d.iteritems()
if k[0] !=
"_")
366 output.update(dfiltered)
374 flstat = open(name, writeflag)
375 flstat.write(
"%s \n" % output)
378 flstat = open(name, writeflag +
'b')
379 cPickle.dump(output, flstat, 2)
382 def write_stats(self):
383 for stat
in self.dictionary_stats.keys():
384 self.write_stat(stat)
386 def get_stat(self, name):
388 for obj
in self.dictionary_stats[name]:
389 output.update(obj.get_output())
395 output=output.Output()
396 output.write_test("test_modeling11_models.rmf_45492_11Sep13_veena_imp-020713.dat",outputobjects)
398 output=output.Output()
399 output.test("test_modeling11_models.rmf_45492_11Sep13_veena_imp-020713.dat",outputobjects)
401 flstat = open(name,
'w')
402 output = self.initoutput
403 for l
in listofobjects:
404 if not "get_test_output" in dir(l)
and not "get_output" in dir(l):
405 print "Output: object ", l,
" doesn't have get_output() or get_test_output() method"
407 self.dictionary_stats[name] = listofobjects
409 for obj
in self.dictionary_stats[name]:
411 d = obj.get_test_output()
415 dfiltered = dict((k, v)
for k, v
in d.iteritems()
if k[0] !=
"_")
416 output.update(dfiltered)
420 flstat.write(
"%s \n" % output)
423 def test(self, name, listofobjects):
424 from numpy.testing
import assert_approx_equal
as aae
425 output = self.initoutput
426 for l
in listofobjects:
427 if not "get_test_output" in dir(l)
and not "get_output" in dir(l):
428 print "Output: object ", l,
" doesn't have get_output() or get_test_output() method"
430 for obj
in listofobjects:
432 output.update(obj.get_test_output())
434 output.update(obj.get_output())
439 flstat = open(name,
'r')
446 old_value = str(test_dict[k])
447 new_value = str(output[k])
449 if test_dict[k] != output[k]:
450 if len(old_value) < 50
and len(new_value) < 50:
451 print str(k) +
": test failed, old value: " + old_value +
" new value " + new_value
454 print str(k) +
": test failed, omitting results (too long)"
458 print str(k) +
" from old objects (file " + str(name) +
") not in new objects"
461 def get_environment_variables(self):
463 return str(os.environ)
465 def get_versions_of_relevant_modules(self):
472 except (ImportError):
476 versions[
"ISD2_VERSION"] = IMP.isd2.get_module_version()
477 except (ImportError):
481 versions[
"ISD_EMXL_VERSION"] = IMP.isd_emxl.get_module_version()
482 except (ImportError):
492 listofsummedobjects=
None):
498 if listofsummedobjects
is None:
499 listofsummedobjects = []
500 if extralabels
is None:
502 flstat = open(name,
'w')
504 stat2_keywords = {
"STAT2HEADER":
"STAT2HEADER"}
505 stat2_keywords.update(
506 {
"STAT2HEADER_ENVIRON": str(self.get_environment_variables())})
507 stat2_keywords.update(
508 {
"STAT2HEADER_IMP_VERSIONS": str(self.get_versions_of_relevant_modules())})
511 for l
in listofobjects:
512 if not "get_output" in dir(l):
513 print "Output: object ", l,
" doesn't have get_output() method"
518 dfiltered = dict((k, v)
519 for k, v
in d.iteritems()
if k[0] !=
"_")
520 output.update(dfiltered)
523 for l
in listofsummedobjects:
525 if not "get_output" in dir(t):
526 print "Output: object ", t,
" doesn't have get_output() method"
529 if "_TotalScore" not in t.get_output():
530 print "Output: object ", t,
" doesn't have _TotalScore entry to be summed"
533 output.update({l[1]: 0.0})
535 for k
in extralabels:
536 output.update({k: 0.0})
538 for n, k
in enumerate(output):
539 stat2_keywords.update({n: k})
540 stat2_inverse.update({k: n})
542 flstat.write(
"%s \n" % stat2_keywords)
544 self.dictionary_stats2[name] = (
550 def write_stat2(self, name, appendmode=True):
552 (listofobjects, stat2_inverse, listofsummedobjects,
553 extralabels) = self.dictionary_stats2[name]
556 for obj
in listofobjects:
557 od = obj.get_output()
558 dfiltered = dict((k, v)
for k, v
in od.iteritems()
if k[0] !=
"_")
560 output.update({stat2_inverse[k]: od[k]})
563 for l
in listofsummedobjects:
567 partial_score += float(d[
"_TotalScore"])
568 output.update({stat2_inverse[l[1]]: str(partial_score)})
571 for k
in extralabels:
572 if k
in self.initoutput:
573 output.update({stat2_inverse[k]: self.initoutput[k]})
575 output.update({stat2_inverse[k]:
"None"})
582 flstat = open(name, writeflag)
583 flstat.write(
"%s \n" % output)
586 def write_stats2(self):
587 for stat
in self.dictionary_stats2.keys():
588 self.write_stat2(stat)
592 """A class for reading stat files"""
593 def __init__(self, filename):
594 self.filename = filename
599 if not self.filename
is None:
600 f = open(self.filename,
"r")
602 print "Error: No file name provided. Use -h for help"
606 for line
in f.readlines():
608 self.klist = d.keys()
610 if "STAT2HEADER" in self.klist:
614 if "STAT2HEADER" in str(k):
620 for k
in sorted(stat2_dict.iteritems(), key=operator.itemgetter(1))]
622 for k
in sorted(stat2_dict.iteritems(), key=operator.itemgetter(1))]
623 self.invstat2_dict = {}
625 self.invstat2_dict.update({stat2_dict[k]: k})
636 def show_keys(self, ncolumns=2, truncate=65):
637 IMP.pmi.tools.print_multicolumn(self.get_keys(), ncolumns, truncate)
646 this function get the wished field names and return a dictionary
647 you can give the optional argument filterout if you want to "grep" out
648 something from the file, so that it is faster
650 filtertuple a tuple that contains ("TheKeyToBeFiltered",relationship,value)
651 relationship = "<", "==", or ">"
659 f = open(self.filename,
"r")
662 for line
in f.readlines():
663 if not filterout
is None:
664 if filterout
in line:
668 if line_number % get_every != 0:
675 print "# Warning: skipped line number " + str(line_number) +
" not a valid line"
680 if not filtertuple
is None:
681 keytobefiltered = filtertuple[0]
682 relationship = filtertuple[1]
683 value = filtertuple[2]
684 if relationship ==
"<":
685 if float(d[keytobefiltered]) >= value:
687 if relationship ==
">":
688 if float(d[keytobefiltered]) <= value:
690 if relationship ==
"==":
691 if float(d[keytobefiltered]) != value:
693 [outdict[field].append(d[field])
for field
in fields]
699 if not filtertuple
is None:
700 keytobefiltered = filtertuple[0]
701 relationship = filtertuple[1]
702 value = filtertuple[2]
703 if relationship ==
"<":
704 if float(d[self.invstat2_dict[keytobefiltered]]) >= value:
706 if relationship ==
">":
707 if float(d[self.invstat2_dict[keytobefiltered]]) <= value:
709 if relationship ==
"==":
710 if float(d[self.invstat2_dict[keytobefiltered]]) != value:
713 [outdict[field].append(d[self.invstat2_dict[field]])
719 def plot_fields(fields, framemin=None, framemax=None):
720 import matplotlib.pyplot
as plt
722 plt.rc(
'lines', linewidth=4)
723 fig, axs = plt.subplots(nrows=len(fields))
724 fig.set_size_inches(10.5, 5.5 * len(fields))
725 plt.rc(
'axes', color_cycle=[
'r'])
732 framemax = len(fields[key])
733 x = range(framemin, framemax)
734 y = [float(y)
for y
in fields[key][framemin:framemax]]
737 axs[n].set_title(key, size=
"xx-large")
738 axs[n].tick_params(labelsize=18, pad=10)
741 axs.set_title(key, size=
"xx-large")
742 axs.tick_params(labelsize=18, pad=10)
746 plt.subplots_adjust(hspace=0.3)
751 name, values_lists, valuename=
None, bins=40, colors=
None, format=
"png",
752 reference_xline=
None, yplotrange=
None, xplotrange=
None,normalized=
True,
755 '''This function is plotting a list of histograms from a value list.
756 @param name the name of the plot
757 @param value_lists the list of list of values eg: [[...],[...],[...]]
758 @param valuename=None the y-label
759 @param bins=40 the number of bins
760 @param colors=None. If None, will use rainbow. Else will use specific list
761 @param format="png" output format
762 @param reference_xline=None plot a reference line parallel to the y-axis
763 @param yplotrange=None the range for the y-axis
764 @param normalized=True whether the histogram is normalized or not
765 @param leg_names names for the legend
768 import matplotlib.pyplot
as plt
769 import matplotlib.cm
as cm
770 fig = plt.figure(figsize=(18.0, 9.0))
773 colors = cm.rainbow(np.linspace(0, 1, len(values_lists)))
774 for nv,values
in enumerate(values_lists):
776 if leg_names
is not None:
781 [float(y)
for y
in values],
784 normed=normalized,histtype=
'step',lw=4,
788 plt.tick_params(labelsize=12, pad=10)
789 if valuename
is None:
790 plt.xlabel(name, size=
"xx-large")
792 plt.xlabel(valuename, size=
"xx-large")
793 plt.ylabel(
"Frequency", size=
"xx-large")
795 if not yplotrange
is None:
797 if not xplotrange
is None:
802 if not reference_xline
is None:
809 plt.savefig(name +
"." + format, dpi=150, transparent=
True)
814 valuename=
"None", positionname=
"None", xlabels=
None):
816 This function plots time series as boxplots
817 fields is a list of time series, positions are the x-values
818 valuename is the y-label, positionname is the x-label
820 import matplotlib.pyplot
as plt
821 from matplotlib.patches
import Polygon
824 fig = plt.figure(figsize=(float(len(positions)) / 2, 5.0))
825 fig.canvas.set_window_title(name)
827 ax1 = fig.add_subplot(111)
829 plt.subplots_adjust(left=0.2, right=0.990, top=0.95, bottom=0.4)
831 bps.append(plt.boxplot(values, notch=0, sym=
'', vert=1,
832 whis=1.5, positions=positions))
834 plt.setp(bps[-1][
'boxes'], color=
'black', lw=1.5)
835 plt.setp(bps[-1][
'whiskers'], color=
'black', ls=
":", lw=1.5)
837 if frequencies
is not None:
838 ax1.plot(positions, frequencies,
'k.', alpha=0.5, markersize=20)
841 if not xlabels
is None:
842 ax1.set_xticklabels(xlabels)
843 plt.xticks(rotation=90)
844 plt.xlabel(positionname)
845 plt.ylabel(valuename)
847 plt.savefig(name,dpi=150)
851 def plot_xy_data(x,y,title=None,display=True,set_plot_yaxis_range=None):
852 import matplotlib.pyplot
as plt
853 plt.rc(
'lines', linewidth=2)
855 fig, ax = plt.subplots(nrows=1)
856 fig.set_size_inches(8,4.5)
857 if title
is not None:
858 fig.canvas.set_window_title(title)
859 plt.rc(
'axes', color_cycle=[
'r'])
861 if title
is not None:
862 plt.savefig(title+
".pdf")
865 if not yplotrange
is None:
866 plt.ylim(set_plot_yaxis_range)
869 def plot_scatter_xy_data(x,y,labelx="None",labely="None",
870 xmin=
None,xmax=
None,ymin=
None,ymax=
None,
871 savefile=
False,filename=
"None.eps",alpha=0.75):
873 import matplotlib.pyplot
as plt
875 from matplotlib
import rc
877 rc(
'font',**{
'family':
'sans-serif',
'sans-serif':[
'Helvetica']})
880 fig, axs = plt.subplots(1)
884 axs0.set_xlabel(labelx, size=
"xx-large")
885 axs0.set_ylabel(labely, size=
"xx-large")
886 axs0.tick_params(labelsize=18, pad=10)
890 plot2.append(axs0.plot(x, y,
'o', color=
'k',lw=2, ms=0.1, alpha=alpha, c=
"w"))
899 fig.set_size_inches(8.0, 8.0)
900 fig.subplots_adjust(left=0.161, right=0.850, top=0.95, bottom=0.11)
901 if (
not ymin
is None)
and (
not ymax
is None):
902 axs0.set_ylim(ymin,ymax)
903 if (
not xmin
is None)
and (
not xmax
is None):
904 axs0.set_xlim(xmin,xmax)
908 fig.savefig(filename, dpi=300)
911 def get_graph_from_hierarchy(hier):
915 (graph, depth, depth_dict) = recursive_graph(
916 hier, graph, depth, depth_dict)
919 node_labels_dict = {}
921 for key
in depth_dict:
922 node_size_dict = 10 / depth_dict[key]
923 if depth_dict[key] < 3:
924 node_labels_dict[key] = key
926 node_labels_dict[key] =
""
927 draw_graph(graph, labels_dict=node_labels_dict)
930 def recursive_graph(hier, graph, depth, depth_dict):
933 index = str(hier.get_particle().
get_index())
934 name1 = nameh +
"|#" + index
935 depth_dict[name1] = depth
939 if len(children) == 1
or children
is None:
941 return (graph, depth, depth_dict)
945 (graph, depth, depth_dict) = recursive_graph(
946 c, graph, depth, depth_dict)
948 index = str(c.get_particle().
get_index())
949 namec = nameh +
"|#" + index
950 graph.append((name1, namec))
953 return (graph, depth, depth_dict)
956 def draw_graph(graph, labels_dict=None, graph_layout='spring',
957 node_size=5, node_color=
None, node_alpha=0.3,
958 node_text_size=11, fixed=
None, pos=
None,
959 edge_color=
'blue', edge_alpha=0.3, edge_thickness=1,
961 validation_edges=
None,
962 text_font=
'sans-serif',
965 import networkx
as nx
966 import matplotlib.pyplot
as plt
967 from math
import sqrt, pi
973 if type(edge_thickness)
is list:
974 for edge,weight
in zip(graph,edge_thickness):
975 G.add_edge(edge[0], edge[1], weight=weight)
978 G.add_edge(edge[0], edge[1])
981 node_color_rgb=(0,0,0)
982 node_color_hex=
"000000"
987 for node
in G.nodes():
988 cctuple=cc.rgb(node_color[node])
989 tmpcolor_rgb.append((cctuple[0]/255,cctuple[1]/255,cctuple[2]/255))
990 tmpcolor_hex.append(node_color[node])
991 node_color_rgb=tmpcolor_rgb
992 node_color_hex=tmpcolor_hex
995 if type(node_size)
is dict:
997 for node
in G.nodes():
998 size=sqrt(node_size[node])/pi*10.0
1002 for n,node
in enumerate(G.nodes()):
1003 color=node_color_hex[n]
1005 nx.set_node_attributes(G,
"graphics", {node : {
'type':
'ellipse',
'w': size,
'h': size,
'fill':
'#'+color,
'label': node}})
1006 nx.set_node_attributes(G,
"LabelGraphics", {node : {
'type':
'text',
'text':node,
'color':
'#000000',
'visible':
'true'}})
1008 for edge
in G.edges():
1009 nx.set_edge_attributes(G,
"graphics", {edge : {
'width': 1,
'fill':
'#000000'}})
1011 for ve
in validation_edges:
1013 if (ve[0],ve[1])
in G.edges():
1014 print "found forward"
1015 nx.set_edge_attributes(G,
"graphics", {ve : {
'width': 1,
'fill':
'#00FF00'}})
1016 elif (ve[1],ve[0])
in G.edges():
1017 print "found backward"
1018 nx.set_edge_attributes(G,
"graphics", {(ve[1],ve[0]) : {
'width': 1,
'fill':
'#00FF00'}})
1020 G.add_edge(ve[0], ve[1])
1022 nx.set_edge_attributes(G,
"graphics", {ve : {
'width': 1,
'fill':
'#FF0000'}})
1026 if graph_layout ==
'spring':
1028 graph_pos = nx.spring_layout(G,k=1.0/8.0,fixed=fixed,pos=pos)
1029 elif graph_layout ==
'spectral':
1030 graph_pos = nx.spectral_layout(G)
1031 elif graph_layout ==
'random':
1032 graph_pos = nx.random_layout(G)
1034 graph_pos = nx.shell_layout(G)
1038 nx.draw_networkx_nodes(G, graph_pos, node_size=node_size,
1039 alpha=node_alpha, node_color=node_color_rgb,
1041 nx.draw_networkx_edges(G, graph_pos, width=edge_thickness,
1042 alpha=edge_alpha, edge_color=edge_color)
1043 nx.draw_networkx_labels(
1044 G, graph_pos, labels=labels_dict, font_size=node_text_size,
1045 font_family=text_font)
1047 plt.savefig(out_filename)
1048 nx.write_gml(G,
'out.gml')
1056 from ipyD3
import d3object
1057 from IPython.display
import display
1059 d3 = d3object(width=800,
1064 title=
'Example table with d3js',
1065 desc=
'An example table created created with d3js with data generated with Python.')
1151 [72.0, 60.0, 60.0, 10.0, 120.0, 172.0, 1092.0, 675.0, 408.0, 360.0, 156.0, 100.0]]
1152 data = [list(i)
for i
in zip(*data)]
1153 sRows = [[
'January',
1165 sColumns = [[
'Prod {0}'.format(i)
for i
in xrange(1, 9)],
1166 [
None,
'',
None,
None,
'Group 1',
None,
None,
'Group 2']]
1167 d3.addSimpleTable(data,
1168 fontSizeCells=[12, ],
1171 sRowsMargins=[5, 50, 0],
1172 sColsMargins=[5, 20, 10],
1175 addOutsideBorders=-1,
1179 html = d3.render(mode=[
'html',
'show'])
void write_pdb(const Selection &mhd, base::TextOutput out, unsigned int model=1)
void save_frame(RMF::FileHandle file, unsigned int, std::string name="")
void add_restraints(RMF::NodeHandle fh, const kernel::Restraints &hs)
A class for reading stat files.
Ints get_index(const kernel::ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
def plot_field_histogram
This function is plotting a list of histograms from a value list.
def plot_fields_box_plots
This function plots time series as boxplots fields is a list of time series, positions are the x-valu...
std::string get_module_version()
def get_fields
this function get the wished field names and return a dictionary you can give the optional argument f...
The standard decorator for manipulating molecular structures.
A decorator for a particle representing an atom.
A decorator for a particle with x,y,z coordinates.
void add_hierarchies(RMF::NodeHandle fh, const atom::Hierarchies &hs)
Class for easy writing of PDBs, RMFs, and stat files.
void add_geometries(RMF::NodeHandle parent, const display::GeometriesTemp &r)
std::string get_module_version()
Display a segment connecting a pair of particles.
static bool get_is_setup(const IMP::kernel::ParticleAdaptor &p)
A decorator for a residue.
Basic functionality that is expected to be used by a wide variety of IMP users.
static bool get_is_setup(const IMP::kernel::ParticleAdaptor &p)
static bool get_is_setup(kernel::Model *m, kernel::ParticleIndex pi)
def write_test
write the test: output=output.Output() output.write_test("test_modeling11_models.rmf_45492_11Sep13_ve...
Python classes to represent, score, sample and analyze models.
Functionality for loading, creating, manipulating and scoring atomic structures.
Hierarchies get_leaves(const Selection &h)
A decorator for a particle with x,y,z coordinates and a radius.