IMP  2.3.0
The Integrative Modeling Platform
solutions_io.py
1 """@namespace IMP.em2d.solutions_io
2  Utility functions to store and retrieve solution information.
3 """
4 
5 import IMP.em2d.imp_general.io as io
6 import IMP.em2d.Database as Database
7 
8 import sys
9 import heapq
10 import math
11 import os
12 import csv
13 import time
14 import logging
15 import glob
16 import numpy as np
17 
18 try:
19  set = set
20 except NameError:
21  from sets import Set as set
22 
23 log = logging.getLogger("solutions_io")
24 
25 unit_delim = "/" # separate units within a field (eg, reference frames).
26 field_delim = ","
27 
28 
29 class ClusterRecord(tuple):
30 
31  """Simple named tuple class"""
32 
33  class _itemgetter(object):
34 
35  def __init__(self, ind):
36  self.__ind = ind
37 
38  def __call__(self, obj):
39  return obj[self.__ind]
40 
41  def __init__(self, iterable):
42  if len(iterable) != self.__n_fields:
43  raise TypeError("Expected %d arguments, got %d"
44  % (self.__n_fields, len(iterable)))
45  tuple.__init__(self, iterable)
46 
47  __n_fields = 5
48  cluster_id = property(_itemgetter(0))
49  n_elements = property(_itemgetter(1))
50  representative = property(_itemgetter(2))
51  elements = property(_itemgetter(3))
52  solutions_ids = property(_itemgetter(4))
53 
54 
55 #
56 
57 # INPUT/OUTPUT OF SOLUTIONS OBTAINED WITH DominoModel
58 
59 #
60 
61 class HeapRecord(tuple):
62 
63  """
64  The heapq algorithm is a min-heap. I want a max-heap, that pops the
65  larger values out of the heap.
66  For that I have to modify the comparison function and also set the
67  index that is used for the comparison. The index corresponds to
68  the restraint that we desired to order by
69  """
70 
71  def __new__(self, x, i):
72  """
73  Build from a tuple and the index used to compare
74  """
75  self.i = i
76  return tuple.__new__(self, x)
77 
78  def __lt__(self, other):
79  """
80  Compare. To convert the min-heap into a max-heap, the lower than
81  comparison is transformed into a greater-than
82  """
83  i = self.i
84  if(self[i] > other[i]):
85  return True
86  return False
87 
88  # Need __le__ as well for older Pythons
89  def __le__(self, other):
90  i = self.i
91  return self[i] >= other[i]
92 
93 
94 def gather_best_solution_results(fns, fn_output, max_number=50000,
95  raisef=0.1, orderby="em2d"):
96  """
97  Reads a set of database files and merge them into a single file.
98 
99  @param fns List of files with databases
100  @param fn_output The database to create
101  @param max_number Maximum number of records to keep, sorted according
102  to orderby
103  @param raisef Ratio of problematic database files tolerated before
104  raising an error. This option is to tolerate some files
105  of the databases being broken because the cluster fails,
106  fill the disks, etc
107  @param orderby Criterium used to sort the the records
108  NOTE:
109  Makes sure to reorder all column names if neccesary before merging
110  The record for the native solution is only added once (from first file).
111  """
112  tbl = "results"
113  # Get names and types of the columns from first database file
114  db = Database.Database2()
115  db.connect(fns[0])
116  names = db.get_table_column_names(tbl)
117  types = db.get_table_types(tbl)
118  indices = get_sorting_indices(names)
119  sorted_names = [names[i] for i in indices]
120  sorted_types = [types[i] for i in indices]
121 
122  names.sort()
123  ind = names.index(orderby)
124  they_are_sorted = field_delim.join(names)
125  # Get the native structure data from the first database
126  sql_command = """SELECT %s FROM %s
127  WHERE assignment="native" LIMIT 1 """ % (they_are_sorted, tbl)
128  native_data = db.retrieve_data(sql_command)
129  db.close()
130  log.info("Gathering results. Saving to %s", fn_output)
131  out_db = Database.Database2()
132  out_db.create(fn_output, overwrite=True)
133  out_db.connect(fn_output)
134  out_db.create_table(tbl, sorted_names, sorted_types)
135 
136  best_records = []
137  n_problems = 0
138  for fn in fns:
139  try:
140  log.info("Reading %s", fn)
141  db.connect(fn)
142 # log.debug("Retrieving %s", they_are_sorted)
143  sql_command = """SELECT %s FROM %s
144  WHERE assignment<>"native"
145  ORDER BY %s ASC LIMIT %s """ % (
146  they_are_sorted, tbl, orderby, max_number)
147  data = db.retrieve_data(sql_command)
148  log.info("%s records read from %s", len(data), fn)
149  db.close()
150  # Fill heap
151  for d in data:
152  a = HeapRecord(d, ind)
153  if(len(best_records) < max_number):
154  heapq.heappush(best_records, a)
155  else:
156  # remember that < here compares for greater em2d value,
157  # as a HeapRecord is used
158  if(best_records[0] < a):
159  heapq.heapreplace(best_records, a)
160  except Exception as e:
161  log.error("Error for %s: %s", fn, e)
162  n_problems += 1
163 
164  # If the number of problematic files is too high, report that something
165  # big is going on. Otherwise tolerate some errors from some tasks that
166  # failed (memory errors, locks, writing errors ...)
167  ratio = float(n_problems) / float(len(fns))
168  if ratio > raisef:
169  raise IOError("There are %8.1f %s of the database "
170  "files to merge with problems! " % (ratio * 100, "%"))
171  # append the native data to the best_records
172  heapq.heappush(best_records, native_data[0])
173  out_db.store_data(tbl, best_records)
174  out_db.close()
175 
176 
177 def gather_solution_results(fns, fn_output, raisef=0.1):
178  """
179  Reads a set of database files and puts them in a single file
180  Makes sure to reorder all column names if neccesary before merging
181  @param fns List of database files
182  @param fn_output Name of the output database
183  @param raisef See help for gather_best_solution_results()
184  """
185  tbl = "results"
186  # Get names and types of the columns from first database file
187  db = Database.Database2()
188  db.connect(fns[0])
189  names = db.get_table_column_names(tbl)
190  types = db.get_table_types(tbl)
191  indices = get_sorting_indices(names)
192  sorted_names = [names[i] for i in indices]
193  sorted_types = [types[i] for i in indices]
194  log.info("Gathering results. Saving to %s", fn_output)
195  out_db = Database.Database2()
196  out_db.create(fn_output, overwrite=True)
197  out_db.connect(fn_output)
198  out_db.create_table(tbl, sorted_names, sorted_types)
199 
200  n_problems = 0
201  for fn in fns:
202  try:
203  log.info("Reading %s", fn)
204  db.connect(fn)
205  names = sorted(db.get_table_column_names(tbl))
206  they_are_sorted = field_delim.join(names)
207  log.debug("Retrieving %s", they_are_sorted)
208  sql_command = "SELECT %s FROM %s" % (they_are_sorted, tbl)
209  data = db.retrieve_data(sql_command)
210  out_db.store_data(tbl, data)
211  db.close()
212  except Exception as e:
213  log.error("Error for file %s: %s", fn, e)
214  n_problems += 1
215  ratio = float(n_problems) / float(len(fns))
216  if ratio > raisef:
217  raise IOError("There are %8.1f %s of the database "
218  "files to merge with problems! " % (ratio * 100, "%"))
219  out_db.close()
220 
221 
223  """ Return indices that sort the list l """
224  pairs = sorted([(element, i) for i, element in enumerate(l)])
225  indices = [p[1] for p in pairs]
226  return indices
227 
228 
229 def get_best_solution(fn_database, Nth, fields=False, orderby=False,
230  tbl="results"):
231  """
232  Recover the reference frame of the n-th best solution from a database.
233  The index Nth stars at 0
234  """
235  f = get_fields_string(fields)
236  sql_command = """ SELECT %s FROM %s
237  ORDER BY %s
238  ASC LIMIT 1 OFFSET %d """ % (f, tbl, orderby, Nth)
239  data = Database.read_data(fn_database, sql_command)
240  if len(data) == 0:
241  raise ValueError("The requested %s-th best solution does not exist. "
242  "Only %s solutions found" % (Nth, len(data)))
243  # the only field last record is the solution requested
244  return data[0][0]
245 
246 
247 def get_pca(string, delimiter="/"):
248  pca = string.split(delimiter)
249  pca = [float(p) for p in pca]
250  return pca
251 
252 
253 def get_fields_string(fields):
254  """
255  Get a list of fields and return a string with them. If there are no
256  fields, return an *, indicating SQL that all the fields are requested
257  @param fields A list of strings
258  @return a string
259  """
260 
261  if fields:
262  return field_delim.join(fields)
263  return "*"
264 
265 
267 
268  """
269  Class for managing the results of the experiments
270  """
271 
272  def __init__(self, ):
273  self.records = []
274  self.native_table_name = "native"
275  self.results_table = "results"
276  self.placements_table = "placements"
277  self.ccc_table_name = "ccc"
278  self.cluster_records = []
279 
280  # columns describing a solution in the results
281  self.results_description_columns = ["solution_id", "assignment",
282  "reference_frames"]
283  self.results_description_types = [int, str, str]
284  # columns describing measures for a result
285  self.results_measures_columns = ["drms", "cdrms", "crmsd"]
286  self.results_measures_types = [float, float, float]
287 
288  def add_results_table(self, restraints_names, add_measures=False):
289  """
290  Build the table of results
291  @param restraints_names The names given to the columns of the table
292  @param add_measures If True, add fields for comparing models
293  and native conformation
294  """
295  table_fields = self.results_description_columns + \
296  ["total_score"] + restraints_names
297  table_types = self.results_description_types + \
298  [float] + [float for r in restraints_names]
299  if add_measures:
300  # Add columns for measures
301  table_fields += self.results_measures_columns
302  table_types += self.results_measures_types
303  log.debug("Creating table %s\n%s", table_fields, table_types)
304  self.create_table(self.results_table, table_fields, table_types)
305  # create a table for the native assembly if we are benchmarking
306  if add_measures:
307  self.create_table(
308  self.native_table_name,
309  table_fields,
310  table_types)
311 
312  def get_solutions_results_table(self, fields=False,
313  max_number=None, orderby=False):
314  """
315  Recovers solutions
316  @param fields Fields to recover from the table
317  @param max_number Maximum number of solutions to recover
318  @param orderby Name of the restraint used for sorting the states
319  """
320  self.check_if_is_connected()
321  log.info("Getting %s from solutions", fields)
322  f = self.get_fields_string(fields)
323  sql_command = "SELECT %s FROM %s " % (f, self.results_table)
324  if orderby:
325  sql_command += " ORDER BY %s ASC" % orderby
326  if max_number not in (None, False):
327  sql_command += " LIMIT %d" % (max_number)
328  log.debug("Using %s", sql_command)
329  data = self.retrieve_data(sql_command)
330  return data
331 
332  def get_solutions(self, fields=False, max_number=None, orderby=False):
333  """
334  Get solutions from the database.
335  @param fields Fields requested. If the fields are in different
336  tables, a left join is done. Otherwise get_solutions_results_table()
337  is called. See get_solutions_results_table() for the meaning
338  of the parameters.
339  @param max_number
340  @param orderby
341  """
342  tables = self.get_tables_names()
343  log.debug("tables %s", tables)
344  required_tables = set()
345  pairs_table_field = []
346 # fields_string = self.get_fields_string(fields)
347  if not fields:
348  fields = ["*", ]
349  for f, t in [(f, t) for f in fields for t in tables]:
350  if t == "native" or f == "solution_id":
351  continue
352  columns = self.get_table_column_names(t)
353  if f in columns:
354  required_tables.add(t)
355  pairs_table_field.append((t, f))
356  required_tables = list(required_tables)
357  log.debug("required_tables %s", required_tables)
358  log.debug("pairs_table_field %s", pairs_table_field)
359  if len(required_tables) == 0:
360  data = self.get_solutions_results_table(fields,
361  max_number, orderby)
362  return data
363  elif len(required_tables) == 1 and required_tables[0] == "results":
364  data = self.get_solutions_results_table(fields,
365  max_number, orderby)
366  return data
367  elif len(required_tables) > 1:
368  sql_command = self.get_left_join_command(pairs_table_field,
369  required_tables)
370  if orderby:
371  sql_command += " ORDER BY %s ASC" % orderby
372  log.debug("Using %s", sql_command)
373  data = self.retrieve_data(sql_command)
374  return data
375  else:
376  raise ValueError("Fields not found in the database")
377 
378  def get_native_solution(self, fields=False):
379  """
380  Recover data for the native solution
381  @param fields Fields to recover
382  """
383 
384  f = self.get_fields_string(fields)
385  sql_command = "SELECT %s FROM %s " % (f, self.native_table_name)
386  data = self.retrieve_data(sql_command)
387  return data
388 
389  def add_record(self, solution_id, assignment, RFs, total_score,
390  restraints_scores, measures):
391  """
392  Add a recorde to the database
393  @param solution_id The key for the solution
394  @param assignment The assigment for the solution provided by
395  domino
396  @param RFs Reference frames of the rigid bodies of the components
397  of the assembly in the solution
398  @param total_score Total value of the scoring function
399  @param restraints_scores A list with all the values for the
400  restraints
401  @param measures A list with the values of all the measures for
402  benchmark
403  """
404  words = [io.ReferenceFrameToText(ref).get_text() for ref in RFs]
405  RFs_txt = unit_delim.join(words)
406  record = [solution_id, assignment, RFs_txt, total_score] + \
407  restraints_scores
408  if measures is not None:
409  record = record + measures
410  self.records.append(record)
411 
412  def add_native_record(self, assignment, RFs, total_score,
413  restraints_scores):
414  """
415  Add a record for the native structure to the database
416  see add_record() for the meaning of the parameters
417  """
418  words = [io.ReferenceFrameToText(ref).get_text() for ref in RFs]
419  RFs_txt = unit_delim.join(words)
420  solution_id = 0
421  record = [solution_id, assignment, RFs_txt, total_score] + \
422  restraints_scores
423  measures = [0, 0, 0] # ["drms", "cdrms", "crmsd"]
424  record = record + measures
425  self.store_data(self.native_table_name, [record])
426 
427  def save_records(self, table="results"):
428  self.store_data(table, self.records)
429 
430  def format_placement_record(self, solution_id, distances, angles):
431  """ both distances and angles are expected to be a list of floats """
432  return [solution_id] + distances + angles
433 
434  def add_placement_scores_table(self, names):
435  """
436  Creates a table to store the values of the placement scores for the
437  models.
438  @param names Names of the components of the assembly
439  """
440  self.check_if_is_connected()
441  self.placement_table_name = self.placements_table
442  table_fields = ["solution_id"]
443  table_fields += ["distance_%s" % name for name in names]
444  table_fields += ["angle_%s" % name for name in names]
445  table_types = [int] + [float for f in table_fields]
446  self.drop_table(self.placement_table_name)
447  self.create_table(self.placement_table_name, table_fields, table_types)
448  self.add_columns(self.native_table_name,
449  table_fields, table_types, check=True)
450  # update all placements scores to 0 for the native assembly
451  native_values = [0 for t in table_fields]
452  log.debug("%s", self.native_table_name)
453  log.debug("table fields %s", table_fields)
454  self.update_data(self.native_table_name,
455  table_fields, native_values,
456  ["assignment"], ["\"native\""])
457 
459  """
460  Return the names of the placement score fields in the database
461  """
462  columns = self.get_table_column_names(self.placements_table)
463  fields = [
464  col for col in columns if "distance" in col or "angle" in col]
465  return fields
466 
467  def add_ccc_table(self):
468  """
469  Add a table to the database for store the values of the cross
470  correlation coefficient between a model and the native configuration
471  """
472 
473  self.check_if_is_connected()
474  table_fields = ["solution_id", "ccc"]
475  table_types = [int, float]
476  self.drop_table(self.ccc_table_name)
477  self.create_table(self.ccc_table_name, table_fields, table_types)
478  # update values for the native assembly
479  self.add_columns(self.native_table_name,
480  table_fields, table_types, check=True)
481  self.update_data(self.native_table_name,
482  table_fields, [0, 1.00], ["assignment"], ["\"native\""])
483 
484  def format_ccc_record(self, solution_id, ccc):
485  """ Format for the record to store in the ccc table """
486  return [solution_id, ccc]
487 
488  def get_ccc(self, solution_id):
489  """
490  Recover the cross-correlation coefficient for a solution
491  @param solution_id
492  """
493  sql_command = """ SELECT ccc FROM %s
494  WHERE solution_id=%d """ % (self.ccc_table_name,
495  solution_id)
496  data = self.retrieve_data(sql_command)
497  return data[0][0]
498 
499  def store_ccc_data(self, ccc_data):
500  self.store_data(self.ccc_table_name, ccc_data)
501 
502  def store_placement_data(self, data):
503  log.debug("store placement table %s", data)
504  self.store_data(self.placement_table_name, data)
505 
506  def get_left_join_command(self, pairs_table_field, tables_names):
507  """
508  Format a left join SQL command that recovers all fileds from the
509  tables given
510  @param pairs_table_field Pairs of (table,field)
511  @param tables_names Names of the tables
512 
513  E.g. If pairs_table_filed = ((table1,a), (table2,b), (table3,c),
514  (table2,d)) and tables_names = (table1, table2, table3)
515 
516  The SQL command is:
517  SELECT table1.a, table2.b, table3.c, table2.d FROM table1
518  LEFT JOIN table2 ON table1.solution_id = table2.solution_id
519  LEFT JOIN table3 ON table1.solution_id = table3.solution_id
520  WHERE table1.solution_id IS NOT NULL AND
521  table2.solution_id IS NOT NULL AND
522  table3.solution_id IS NOT NULL
523  """
524 
525  txt = ["%s.%s" % (p[0], p[1]) for p in pairs_table_field]
526  fields_requested = field_delim.join(txt)
527  sql_command = " SELECT %s FROM %s " % (
528  fields_requested, tables_names[0])
529  n_tables = len(tables_names)
530  for i in range(1, n_tables):
531  a = tables_names[i - 1]
532  b = tables_names[i]
533  sql_command += " LEFT JOIN %s " \
534  "ON %s.solution_id = %s.solution_id " % (b, a, b)
535  # add the condition of solution_id being not null, so there are not
536  # problems if some solutions are missing in one table
537  for i in range(n_tables - 1):
538  sql_command += "WHERE %s.solution_id " \
539  "IS NOT NULL AND " % tables_names[
540  i]
541  sql_command += " %s.solution_id IS NOT NULL " % tables_names[
542  n_tables - 1]
543  log.debug("%s" % sql_command)
544  return sql_command
545 
546  def add_clusters_table(self, name):
547  """
548  Add a table to store information about the clusters of structures
549  @param name Name of the table
550  """
551  self.cluster_table_name = name
552  self.check_if_is_connected()
553  table_fields = ("cluster_id", "n_elements",
554  "representative", "elements", "solutions_ids")
555  table_types = (int, int, int, str, str)
556  self.drop_table(name)
557  self.create_table(name, table_fields, table_types)
558 
559  def add_cluster_record(self, cluster_id, n_elements, representative,
560  elements, solutions_ids):
561  """
562  Add a record to the cluster database. Actually, only stores it
563  in a list (that will be added later)
564  @param cluster_id Number with the id of the cluster
565  @param n_elements Number of elements in the cluster
566  @param representative Number with the id of the representative
567  element
568  @param elements List with the number of the elements of the cluster
569  @param solutions_ids The numbers above are provided by the
570  clustering algorithm. The solutions_ids are the ids of the models
571  in "elements".
572  """
573 
574  record = (cluster_id, n_elements, representative, elements,
575  solutions_ids)
576  log.debug("Adding cluster record: %s", record)
577  self.cluster_records.append(record)
578 
580  """
581  Store the data for the clusters
582  """
583  log.info("Storing data of clusters. Number of records %s",
584  len(self.cluster_records))
585  self.store_data(self.cluster_table_name, self.cluster_records)
586 
587  def get_solutions_from_list(self, fields=False, solutions_ids=[]):
588  """
589  Recover solutions for a specific list of results
590  @param fields Fields to recover fro the database
591  @param solutions_ids A list with the desired solutions. E.g. [0,3,6]
592  """
593  sql_command = """ SELECT %s FROM %s WHERE solution_id IN (%s) """
594  f = self.get_fields_string(fields)
595  str_ids = ",".join(map(str, solutions_ids))
596  data = self.retrieve_data(
597  sql_command %
598  (f, self.results_table, str_ids))
599  return data
600 
601  def get_native_rank(self, orderby):
602  """
603  Get the position of the native configuration
604  @param orderby Criterium used to sort the solutions
605  """
606  import numpy as np
607 
608  data = self.get_native_solution([orderby, ])
609  native_value = data[0][0]
610  data = self.get_solutions_results_table(fields=[orderby, ],
611  orderby=orderby)
612  values = [row[0] for row in data]
613  rank = np.searchsorted(values, native_value)
614  return rank
615 
616  def get_nth_largest_cluster(self, position, table_name="clusters"):
617  """
618  Recover the the information about the n-th largest cluster
619  @param position Cluster position (by size) requested
620  (1 is the largest cluster)
621  @param table_name Table where the information about the
622  clusters is stored
623  """
624  s = """ SELECT * FROM %s ORDER BY n_elements DESC """ % table_name
625  data = self.retrieve_data(s)
626  record = ClusterRecord(data[position - 1])
627  return record
628 
629  def get_individual_placement_statistics(self, solutions_ids):
630  """
631  Recovers from the database the placement scores for a set of
632  solutions, and returns the mean and standard deviation of the
633  placement score for each of the components of the complex being
634  scored. This function will be typical used to compute the variation
635  of the placement of each component within a cluster of solutions
636  @param solutions_ids The ids of the solutions used to compute
637  the statistics
638  @return The output are 4 numpy vectors:
639  placement_distances_mean - The mean placement distance for each
640  component
641  placement_distances_stddev - The standardd deviation of the
642  placement distance for each component
643  placement_angles_mean - The mean placement angle for each
644  component
645  placement_angles_stddev - The standard deviation of the placement
646  angle for each component,
647  """
648 
649  self.check_if_is_connected()
650  table = self.placements_table
651  fields = self.get_table_column_names(table)
652  distance_fields = filter(lambda x: 'distance' in x, fields)
653  angle_fields = filter(lambda x: 'angle' in x, fields)
654  sql_command = """ SELECT %s FROM %s WHERE solution_id IN (%s) """
655  # string with the solution ids to pass to the sql_command
656  str_ids = ",".join(map(str, solutions_ids))
657  log.debug("Solutions considered %s", solutions_ids)
658  s = sql_command % (",".join(distance_fields), table, str_ids)
659  data_distances = self.retrieve_data(s)
660  s = sql_command % (",".join(angle_fields), table, str_ids)
661  data_angles = self.retrieve_data(s)
662  D = np.array(data_distances)
663  placement_distances_mean = D.mean(axis=0)
664  placement_distances_stddev = D.std(axis=0)
665  A = np.array(data_angles)
666  placement_angles_mean = A.mean(axis=0)
667  placement_angles_stddev = A.std(axis=0)
668  return [placement_distances_mean, placement_distances_stddev,
669  placement_angles_mean, placement_angles_stddev]
670 
671  def get_placement_statistics(self, solutions_ids):
672  """
673  Calculate the placement score and its standard deviation for
674  the complexes in a set of solutions. The values returned are
675  averages, as the placement score for a complex is the average
676  of the placement scores of the components. This function is used
677  to obtain global placement for a cluster of solutions.
678  @param solutions_ids The ids of the solutions used to compute
679  the statistics
680  @return The output are 4 values:
681  plcd_mean - Average of the placement distance for the entire
682  complex over all the solutions.
683  plcd_std - Standard deviation of the placement distance for
684  the entire complex over all the solutions.
685  plca_mean - Average of the placement angle for the entire
686  complex over all the solutions.
687  plca_std - Standard deviation of the placement angle for
688  the entire complex over all the solutions.
689  """
690  [placement_distances_mean, placement_distances_stddev,
691  placement_angles_mean, placement_angles_stddev] = \
692  self.get_individual_placement_statistics(solutions_ids)
693  plcd_mean = placement_distances_mean.mean(axis=0)
694  plcd_std = placement_distances_stddev.mean(axis=0)
695  plca_mean = placement_angles_mean.mean(axis=0)
696  plca_std = placement_angles_stddev.mean(axis=0)
697  return [plcd_mean, plcd_std, plca_mean, plca_std]
def format_placement_record
both distances and angles are expected to be a list of floats
def add_placement_scores_table
Creates a table to store the values of the placement scores for the models.
def check_if_is_connected
Checks if the class is connected to the database filename.
Definition: Database.py:39
Utility functions to manage SQL databases with sqlite3.
Definition: Database.py:1
def get_solutions
Get solutions from the database.
def get_solutions_results_table
Recovers solutions.
def get_best_solution
Recover the reference frame of the n-th best solution from a database.
def store_data
Inserts information in a given table of the database.
Definition: Database.py:94
def get_sorting_indices
Return indices that sort the list l.
def retrieve_data
Retrieves data from the database using the sql_command returns the records as a list of tuples...
Definition: Database.py:116
def get_table_column_names
Get the names of the columns for a given table.
Definition: Database.py:229
def update_data
updates the register in the table identified by the condition values for the condition fields ...
Definition: Database.py:124
def format_ccc_record
Format for the record to store in the ccc table.
def add_ccc_table
Add a table to the database for store the values of the cross correlation coefficient between a model...
def get_placement_statistics
Calculate the placement score and its standard deviation for the complexes in a set of solutions...
Simple named tuple class.
Definition: solutions_io.py:29
def add_results_table
Build the table of results.
def get_nth_largest_cluster
Recover the the information about the n-th largest cluster.
def add_columns
Add columns to the database.
Definition: Database.py:255
def drop_table
Delete a table if it exists.
Definition: Database.py:61
def get_solutions_from_list
Recover solutions for a specific list of results.
Class to manage a SQL database built with sqlite3.
Definition: Database.py:13
def add_native_record
Add a record for the native structure to the database see add_record() for the meaning of the paramet...
def add_record
Add a recorde to the database.
def store_cluster_data
Store the data for the clusters.
def gather_solution_results
Reads a set of database files and puts them in a single file Makes sure to reorder all column names i...
Class for managing the results of the experiments.
def get_native_rank
Get the position of the native configuration.
def create_table
Creates a table.
Definition: Database.py:45
def get_individual_placement_statistics
Recovers from the database the placement scores for a set of solutions, and returns the mean and stan...
def get_fields_string
Get a list of fields and return a string with them.
The heapq algorithm is a min-heap.
Definition: solutions_io.py:61
def get_native_solution
Recover data for the native solution.
def get_ccc
Recover the cross-correlation coefficient for a solution.
def get_left_join_command
Format a left join SQL command that recovers all fileds from the tables given.
def get_placement_fields
Return the names of the placement score fields in the database.
def add_clusters_table
Add a table to store information about the clusters of structures.
def add_cluster_record
Add a record to the cluster database.
def gather_best_solution_results
Reads a set of database files and merge them into a single file.
Definition: solutions_io.py:94