1 """@namespace IMP.pmi.output
2 Classes for writing output files and processing them.
15 import cPickle
as pickle
20 """Class for easy writing of PDBs, RMFs, and stat files"""
21 def __init__(self, ascii=True,atomistic=False):
22 self.dictionary_pdbs = {}
23 self.dictionary_rmfs = {}
24 self.dictionary_stats = {}
25 self.dictionary_stats2 = {}
26 self.best_score_list =
None
27 self.nbestscoring =
None
29 self.replica_exchange =
False
33 self.chainids =
"ABCDEFGHIJKLMNOPQRSTUVXYWZabcdefghijklmnopqrstuvxywz"
35 self.particle_infos_for_pdb = {}
36 self.atomistic=atomistic
38 def get_pdb_names(self):
39 return self.dictionary_pdbs.keys()
41 def get_rmf_names(self):
42 return self.dictionary_rmfs.keys()
44 def get_stat_names(self):
45 return self.dictionary_stats.keys()
47 def init_pdb(self, name, prot):
48 flpdb = open(name,
'w')
50 self.dictionary_pdbs[name] = prot
51 self.dictchain[name] = {}
53 for n, i
in enumerate(self.dictionary_pdbs[name].get_children()):
54 self.dictchain[name][i.get_name()] = self.chainids[n]
57 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(
"ENDMDL\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"
273 if os.path.exists(newname):
275 os.rename(oldname, newname)
276 filetoadd = suffix +
"." + str(index) +
".pdb"
277 self.write_pdb(filetoadd, appendmode=
False)
280 if score < self.best_score_list[-1]:
281 self.best_score_list.append(score)
282 self.best_score_list.sort()
283 self.best_score_list.pop(-1)
284 index = self.best_score_list.index(score)
285 for suffix
in self.suffixes:
286 for i
in range(len(self.best_score_list) - 1, index - 1, -1):
287 oldname = suffix +
"." + str(i) +
".pdb"
288 newname = suffix +
"." + str(i + 1) +
".pdb"
289 os.rename(oldname, newname)
290 filenametoremove = suffix + \
291 "." + str(self.nbestscoring) +
".pdb"
292 os.remove(filenametoremove)
293 filetoadd = suffix +
"." + str(index) +
".pdb"
294 self.write_pdb(filetoadd, appendmode=
False)
296 if self.replica_exchange:
298 best_score_file = open(self.best_score_file_name,
"w")
299 best_score_file.write(
300 "self.best_score_list=" + str(self.best_score_list))
301 best_score_file.close()
303 def init_rmf(self, name, hierarchies,rs=None):
304 rh = RMF.create_rmf_file(name)
308 self.dictionary_rmfs[name] = rh
310 def add_restraints_to_rmf(self, name, objectlist):
313 rs = o.get_restraint_for_rmf()
315 rs = o.get_restraint()
317 self.dictionary_rmfs[name],
320 def add_geometries_to_rmf(self, name, objectlist):
322 geos = o.get_geometries()
325 def add_particle_pair_from_restraints_to_rmf(self, name, objectlist):
328 pps = o.get_particle_pairs()
330 IMP.rmf.add_geometry(
331 self.dictionary_rmfs[name],
334 def write_rmf(self, name):
336 self.dictionary_rmfs[name].flush()
338 def close_rmf(self, name):
339 del self.dictionary_rmfs[name]
341 def write_rmfs(self):
342 for rmf
in self.dictionary_rmfs.keys():
345 def init_stat(self, name, listofobjects):
347 flstat = open(name,
'w')
350 flstat = open(name,
'wb')
354 for l
in listofobjects:
355 if not "get_output" in dir(l):
356 raise ValueError(
"Output: object %s doesn't have get_output() method" % str(l))
357 self.dictionary_stats[name] = listofobjects
359 def set_output_entry(self, key, value):
360 self.initoutput.update({key: value})
362 def write_stat(self, name, appendmode=True):
363 output = self.initoutput
364 for obj
in self.dictionary_stats[name]:
367 dfiltered = dict((k, v)
for k, v
in d.iteritems()
if k[0] !=
"_")
368 output.update(dfiltered)
376 flstat = open(name, writeflag)
377 flstat.write(
"%s \n" % output)
380 flstat = open(name, writeflag +
'b')
381 cPickle.dump(output, flstat, 2)
384 def write_stats(self):
385 for stat
in self.dictionary_stats.keys():
386 self.write_stat(stat)
388 def get_stat(self, name):
390 for obj
in self.dictionary_stats[name]:
391 output.update(obj.get_output())
397 output=output.Output()
398 output.write_test("test_modeling11_models.rmf_45492_11Sep13_veena_imp-020713.dat",outputobjects)
400 output=output.Output()
401 output.test("test_modeling11_models.rmf_45492_11Sep13_veena_imp-020713.dat",outputobjects)
403 flstat = open(name,
'w')
404 output = self.initoutput
405 for l
in listofobjects:
406 if not "get_test_output" in dir(l)
and not "get_output" in dir(l):
407 raise ValueError(
"Output: object %s doesn't have get_output() or get_test_output() method" % str(l))
408 self.dictionary_stats[name] = listofobjects
410 for obj
in self.dictionary_stats[name]:
412 d = obj.get_test_output()
416 dfiltered = dict((k, v)
for k, v
in d.iteritems()
if k[0] !=
"_")
417 output.update(dfiltered)
421 flstat.write(
"%s \n" % output)
424 def test(self, name, listofobjects):
425 from numpy.testing
import assert_approx_equal
as aae
426 output = self.initoutput
427 for l
in listofobjects:
428 if not "get_test_output" in dir(l)
and not "get_output" in dir(l):
429 raise ValueError(
"Output: object %s doesn't have get_output() or get_test_output() method" % str(l))
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 raise ValueError(
"Output: object %s doesn't have get_output() method" % str(l))
517 dfiltered = dict((k, v)
518 for k, v
in d.iteritems()
if k[0] !=
"_")
519 output.update(dfiltered)
522 for l
in listofsummedobjects:
524 if not "get_output" in dir(t):
525 raise ValueError(
"Output: object %s doesn't have get_output() method" % str(t))
527 if "_TotalScore" not in t.get_output():
528 raise ValueError(
"Output: object %s doesn't have _TotalScore entry to be summed" % str(t))
530 output.update({l[1]: 0.0})
532 for k
in extralabels:
533 output.update({k: 0.0})
535 for n, k
in enumerate(output):
536 stat2_keywords.update({n: k})
537 stat2_inverse.update({k: n})
539 flstat.write(
"%s \n" % stat2_keywords)
541 self.dictionary_stats2[name] = (
547 def write_stat2(self, name, appendmode=True):
549 (listofobjects, stat2_inverse, listofsummedobjects,
550 extralabels) = self.dictionary_stats2[name]
553 for obj
in listofobjects:
554 od = obj.get_output()
555 dfiltered = dict((k, v)
for k, v
in od.iteritems()
if k[0] !=
"_")
557 output.update({stat2_inverse[k]: od[k]})
560 for l
in listofsummedobjects:
564 partial_score += float(d[
"_TotalScore"])
565 output.update({stat2_inverse[l[1]]: str(partial_score)})
568 for k
in extralabels:
569 if k
in self.initoutput:
570 output.update({stat2_inverse[k]: self.initoutput[k]})
572 output.update({stat2_inverse[k]:
"None"})
579 flstat = open(name, writeflag)
580 flstat.write(
"%s \n" % output)
583 def write_stats2(self):
584 for stat
in self.dictionary_stats2.keys():
585 self.write_stat2(stat)
589 """A class for reading stat files"""
590 def __init__(self, filename):
591 self.filename = filename
596 if not self.filename
is None:
597 f = open(self.filename,
"r")
599 raise ValueError(
"No file name provided. Use -h for help")
602 for line
in f.readlines():
604 self.klist = d.keys()
606 if "STAT2HEADER" in self.klist:
609 if "STAT2HEADER" in str(k):
615 for k
in sorted(stat2_dict.iteritems(), key=operator.itemgetter(1))]
617 for k
in sorted(stat2_dict.iteritems(), key=operator.itemgetter(1))]
618 self.invstat2_dict = {}
620 self.invstat2_dict.update({stat2_dict[k]: k})
631 def show_keys(self, ncolumns=2, truncate=65):
632 IMP.pmi.tools.print_multicolumn(self.get_keys(), ncolumns, truncate)
641 this function get the wished field names and return a dictionary
642 you can give the optional argument filterout if you want to "grep" out
643 something from the file, so that it is faster
645 filtertuple a tuple that contains ("TheKeyToBeFiltered",relationship,value)
646 relationship = "<", "==", or ">"
654 f = open(self.filename,
"r")
657 for line
in f.readlines():
658 if not filterout
is None:
659 if filterout
in line:
663 if line_number % get_every != 0:
670 print "# Warning: skipped line number " + str(line_number) +
" not a valid line"
675 if not filtertuple
is None:
676 keytobefiltered = filtertuple[0]
677 relationship = filtertuple[1]
678 value = filtertuple[2]
679 if relationship ==
"<":
680 if float(d[keytobefiltered]) >= value:
682 if relationship ==
">":
683 if float(d[keytobefiltered]) <= value:
685 if relationship ==
"==":
686 if float(d[keytobefiltered]) != value:
688 [outdict[field].append(d[field])
for field
in fields]
694 if not filtertuple
is None:
695 keytobefiltered = filtertuple[0]
696 relationship = filtertuple[1]
697 value = filtertuple[2]
698 if relationship ==
"<":
699 if float(d[self.invstat2_dict[keytobefiltered]]) >= value:
701 if relationship ==
">":
702 if float(d[self.invstat2_dict[keytobefiltered]]) <= value:
704 if relationship ==
"==":
705 if float(d[self.invstat2_dict[keytobefiltered]]) != value:
708 [outdict[field].append(d[self.invstat2_dict[field]])
714 def plot_fields(fields, framemin=None, framemax=None):
715 import matplotlib
as mpl
717 import matplotlib.pyplot
as plt
719 plt.rc(
'lines', linewidth=4)
720 fig, axs = plt.subplots(nrows=len(fields))
721 fig.set_size_inches(10.5, 5.5 * len(fields))
722 plt.rc(
'axes', color_cycle=[
'r'])
729 framemax = len(fields[key])
730 x = range(framemin, framemax)
731 y = [float(y)
for y
in fields[key][framemin:framemax]]
734 axs[n].set_title(key, size=
"xx-large")
735 axs[n].tick_params(labelsize=18, pad=10)
738 axs.set_title(key, size=
"xx-large")
739 axs.tick_params(labelsize=18, pad=10)
743 plt.subplots_adjust(hspace=0.3)
748 name, values_lists, valuename=
None, bins=40, colors=
None, format=
"png",
749 reference_xline=
None, yplotrange=
None, xplotrange=
None,normalized=
True,
752 '''This function is plotting a list of histograms from a value list.
753 @param name the name of the plot
754 @param value_lists the list of list of values eg: [[...],[...],[...]]
755 @param valuename=None the y-label
756 @param bins=40 the number of bins
757 @param colors=None. If None, will use rainbow. Else will use specific list
758 @param format="png" output format
759 @param reference_xline=None plot a reference line parallel to the y-axis
760 @param yplotrange=None the range for the y-axis
761 @param normalized=True whether the histogram is normalized or not
762 @param leg_names names for the legend
765 import matplotlib
as mpl
767 import matplotlib.pyplot
as plt
768 import matplotlib.cm
as cm
769 fig = plt.figure(figsize=(18.0, 9.0))
772 colors = cm.rainbow(np.linspace(0, 1, len(values_lists)))
773 for nv,values
in enumerate(values_lists):
775 if leg_names
is not None:
780 [float(y)
for y
in values],
783 normed=normalized,histtype=
'step',lw=4,
787 plt.tick_params(labelsize=12, pad=10)
788 if valuename
is None:
789 plt.xlabel(name, size=
"xx-large")
791 plt.xlabel(valuename, size=
"xx-large")
792 plt.ylabel(
"Frequency", size=
"xx-large")
794 if not yplotrange
is None:
796 if not xplotrange
is None:
801 if not reference_xline
is None:
808 plt.savefig(name +
"." + format, dpi=150, transparent=
True)
813 valuename=
"None", positionname=
"None", xlabels=
None):
815 This function plots time series as boxplots
816 fields is a list of time series, positions are the x-values
817 valuename is the y-label, positionname is the x-label
819 import matplotlib
as mpl
821 import matplotlib.pyplot
as plt
822 from matplotlib.patches
import Polygon
825 fig = plt.figure(figsize=(float(len(positions)) / 2, 5.0))
826 fig.canvas.set_window_title(name)
828 ax1 = fig.add_subplot(111)
830 plt.subplots_adjust(left=0.2, right=0.990, top=0.95, bottom=0.4)
832 bps.append(plt.boxplot(values, notch=0, sym=
'', vert=1,
833 whis=1.5, positions=positions))
835 plt.setp(bps[-1][
'boxes'], color=
'black', lw=1.5)
836 plt.setp(bps[-1][
'whiskers'], color=
'black', ls=
":", lw=1.5)
838 if frequencies
is not None:
839 ax1.plot(positions, frequencies,
'k.', alpha=0.5, markersize=20)
842 if not xlabels
is None:
843 ax1.set_xticklabels(xlabels)
844 plt.xticks(rotation=90)
845 plt.xlabel(positionname)
846 plt.ylabel(valuename)
848 plt.savefig(name,dpi=150)
852 def plot_xy_data(x,y,title=None,out_fn=None,display=True,set_plot_yaxis_range=None,
853 xlabel=
None,ylabel=
None):
854 import matplotlib
as mpl
856 import matplotlib.pyplot
as plt
857 plt.rc(
'lines', linewidth=2)
859 fig, ax = plt.subplots(nrows=1)
860 fig.set_size_inches(8,4.5)
861 if title
is not None:
862 fig.canvas.set_window_title(title)
865 ax.plot(x,y,color=
'r')
866 if set_plot_yaxis_range
is not None:
867 x1,x2,y1,y2=plt.axis()
868 y1=set_plot_yaxis_range[0]
869 y2=set_plot_yaxis_range[1]
870 plt.axis((x1,x2,y1,y2))
871 if title
is not None:
873 if xlabel
is not None:
874 ax.set_xlabel(xlabel)
875 if ylabel
is not None:
876 ax.set_ylabel(ylabel)
877 if out_fn
is not None:
878 plt.savefig(out_fn+
".pdf")
883 def plot_scatter_xy_data(x,y,labelx="None",labely="None",
884 xmin=
None,xmax=
None,ymin=
None,ymax=
None,
885 savefile=
False,filename=
"None.eps",alpha=0.75):
887 import matplotlib
as mpl
889 import matplotlib.pyplot
as plt
891 from matplotlib
import rc
893 rc(
'font',**{
'family':
'sans-serif',
'sans-serif':[
'Helvetica']})
896 fig, axs = plt.subplots(1)
900 axs0.set_xlabel(labelx, size=
"xx-large")
901 axs0.set_ylabel(labely, size=
"xx-large")
902 axs0.tick_params(labelsize=18, pad=10)
906 plot2.append(axs0.plot(x, y,
'o', color=
'k',lw=2, ms=0.1, alpha=alpha, c=
"w"))
915 fig.set_size_inches(8.0, 8.0)
916 fig.subplots_adjust(left=0.161, right=0.850, top=0.95, bottom=0.11)
917 if (
not ymin
is None)
and (
not ymax
is None):
918 axs0.set_ylim(ymin,ymax)
919 if (
not xmin
is None)
and (
not xmax
is None):
920 axs0.set_xlim(xmin,xmax)
924 fig.savefig(filename, dpi=300)
927 def get_graph_from_hierarchy(hier):
931 (graph, depth, depth_dict) = recursive_graph(
932 hier, graph, depth, depth_dict)
935 node_labels_dict = {}
937 for key
in depth_dict:
938 node_size_dict = 10 / depth_dict[key]
939 if depth_dict[key] < 3:
940 node_labels_dict[key] = key
942 node_labels_dict[key] =
""
943 draw_graph(graph, labels_dict=node_labels_dict)
946 def recursive_graph(hier, graph, depth, depth_dict):
949 index = str(hier.get_particle().
get_index())
950 name1 = nameh +
"|#" + index
951 depth_dict[name1] = depth
955 if len(children) == 1
or children
is None:
957 return (graph, depth, depth_dict)
961 (graph, depth, depth_dict) = recursive_graph(
962 c, graph, depth, depth_dict)
964 index = str(c.get_particle().
get_index())
965 namec = nameh +
"|#" + index
966 graph.append((name1, namec))
969 return (graph, depth, depth_dict)
972 def draw_graph(graph, labels_dict=None, graph_layout='spring',
973 node_size=5, node_color=
None, node_alpha=0.3,
974 node_text_size=11, fixed=
None, pos=
None,
975 edge_color=
'blue', edge_alpha=0.3, edge_thickness=1,
977 validation_edges=
None,
978 text_font=
'sans-serif',
981 import matplotlib
as mpl
983 import networkx
as nx
984 import matplotlib.pyplot
as plt
985 from math
import sqrt, pi
991 if type(edge_thickness)
is list:
992 for edge,weight
in zip(graph,edge_thickness):
993 G.add_edge(edge[0], edge[1], weight=weight)
996 G.add_edge(edge[0], edge[1])
999 node_color_rgb=(0,0,0)
1000 node_color_hex=
"000000"
1005 for node
in G.nodes():
1006 cctuple=cc.rgb(node_color[node])
1007 tmpcolor_rgb.append((cctuple[0]/255,cctuple[1]/255,cctuple[2]/255))
1008 tmpcolor_hex.append(node_color[node])
1009 node_color_rgb=tmpcolor_rgb
1010 node_color_hex=tmpcolor_hex
1013 if type(node_size)
is dict:
1015 for node
in G.nodes():
1016 size=sqrt(node_size[node])/pi*10.0
1017 tmpsize.append(size)
1020 for n,node
in enumerate(G.nodes()):
1021 color=node_color_hex[n]
1023 nx.set_node_attributes(G,
"graphics", {node : {
'type':
'ellipse',
'w': size,
'h': size,
'fill':
'#'+color,
'label': node}})
1024 nx.set_node_attributes(G,
"LabelGraphics", {node : {
'type':
'text',
'text':node,
'color':
'#000000',
'visible':
'true'}})
1026 for edge
in G.edges():
1027 nx.set_edge_attributes(G,
"graphics", {edge : {
'width': 1,
'fill':
'#000000'}})
1029 for ve
in validation_edges:
1031 if (ve[0],ve[1])
in G.edges():
1032 print "found forward"
1033 nx.set_edge_attributes(G,
"graphics", {ve : {
'width': 1,
'fill':
'#00FF00'}})
1034 elif (ve[1],ve[0])
in G.edges():
1035 print "found backward"
1036 nx.set_edge_attributes(G,
"graphics", {(ve[1],ve[0]) : {
'width': 1,
'fill':
'#00FF00'}})
1038 G.add_edge(ve[0], ve[1])
1040 nx.set_edge_attributes(G,
"graphics", {ve : {
'width': 1,
'fill':
'#FF0000'}})
1044 if graph_layout ==
'spring':
1046 graph_pos = nx.spring_layout(G,k=1.0/8.0,fixed=fixed,pos=pos)
1047 elif graph_layout ==
'spectral':
1048 graph_pos = nx.spectral_layout(G)
1049 elif graph_layout ==
'random':
1050 graph_pos = nx.random_layout(G)
1052 graph_pos = nx.shell_layout(G)
1056 nx.draw_networkx_nodes(G, graph_pos, node_size=node_size,
1057 alpha=node_alpha, node_color=node_color_rgb,
1059 nx.draw_networkx_edges(G, graph_pos, width=edge_thickness,
1060 alpha=edge_alpha, edge_color=edge_color)
1061 nx.draw_networkx_labels(
1062 G, graph_pos, labels=labels_dict, font_size=node_text_size,
1063 font_family=text_font)
1065 plt.savefig(out_filename)
1066 nx.write_gml(G,
'out.gml')
1074 from ipyD3
import d3object
1075 from IPython.display
import display
1077 d3 = d3object(width=800,
1082 title=
'Example table with d3js',
1083 desc=
'An example table created created with d3js with data generated with Python.')
1169 [72.0, 60.0, 60.0, 10.0, 120.0, 172.0, 1092.0, 675.0, 408.0, 360.0, 156.0, 100.0]]
1170 data = [list(i)
for i
in zip(*data)]
1171 sRows = [[
'January',
1183 sColumns = [[
'Prod {0}'.format(i)
for i
in xrange(1, 9)],
1184 [
None,
'',
None,
None,
'Group 1',
None,
None,
'Group 2']]
1185 d3.addSimpleTable(data,
1186 fontSizeCells=[12, ],
1189 sRowsMargins=[5, 50, 0],
1190 sColsMargins=[5, 20, 10],
1193 addOutsideBorders=-1,
1197 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.