Exemplo n.º 1
0
 def _get_comp(self, molecule, property, details, generate):
     for comp in self.computations:
         # TODO offer both "is" and "==" (as well as "is_same_molecule") options
         if comp.molecule is molecule:
             for prop in comp.properties:
                 if MolecularProperty.is_same_property(prop, property):
                     if details is None or details.is_subset_of(prop.details):
                         return comp
     # well, we couldn't find one.  Should we make one?
     if generate:
         if 'property' in self.computation_kwargs:
             prop = self.computation_kwargs['property']
             if not MolecularProperty.is_same_property(prop, property):
                 raise ComputationUnavailableError("property mismatch.  Can't generate computation"
                                                   " of property '{}'".format(
                     MolecularProperty.property_type_of(property).__name__
                 ))
             # This will append the computation to the self.computations list automatically
             comp = Computation(molecule=molecule, result_getter=self, **self.computation_kwargs)
         else:
             # This will append the computation to the self.computations list automatically
             comp = Computation(molecule=molecule, property=property, result_getter=self, **self.computation_kwargs)
         return comp
     else:
         return None
Exemplo n.º 2
0
 def _get_comp(self, molecule, property, details, generate):
     for comp in self.computations:
         # TODO offer both "is" and "==" (as well as "is_same_molecule") options
         if comp.molecule is molecule:
             for prop in comp.properties:
                 if MolecularProperty.is_same_property(prop, property):
                     if details is None or details.is_subset_of(
                             prop.details):
                         return comp
     # well, we couldn't find one.  Should we make one?
     if generate:
         if 'property' in self.computation_kwargs:
             prop = self.computation_kwargs['property']
             if not MolecularProperty.is_same_property(prop, property):
                 raise ComputationUnavailableError(
                     "property mismatch.  Can't generate computation"
                     " of property '{}'".format(
                         MolecularProperty.property_type_of(
                             property).__name__))
             # This will append the computation to the self.computations list automatically
             comp = Computation(molecule=molecule,
                                result_getter=self,
                                **self.computation_kwargs)
         else:
             # This will append the computation to the self.computations list automatically
             comp = Computation(molecule=molecule,
                                property=property,
                                result_getter=self,
                                **self.computation_kwargs)
         return comp
     else:
         return None
Exemplo n.º 3
0
 def valid_parsers(self):
     valid_parsers = {}
     for property in self.needed_properties:
         for parser in self.property_parsers:
             if parser.compatible_with_details(self.computation.details):
                 if MolecularProperty.is_same_property(property, parser.property):
                     valid_parsers[property.property_type] = parser
                     break
         if not any(MolecularProperty.is_same_property(property, p) for p in valid_parsers):
             raise ComputationUnavailableError("Could not find a valid parser for {0} in class {1} compatible with details: "
                              "\n{2}".format(property.property_type.__name__, classname(self.__class__), self.computation.details))
     return valid_parsers
Exemplo n.º 4
0
 def get_property_for_molecule(self, molecule, property, details=None):
     for p in self.properties_for_molecules[molecule]:
         if MolecularProperty.is_same_property(property, p):
             if ComputationDetails.is_compatible_details(details, p.details):
                 return p
     props = self.properties[molecule]
     for p in props:
         pcopy = copy(p)
         pcopy.molecule = molecule
         self.properties_for_molecules[molecule].append(pcopy)
         if MolecularProperty.is_same_property(property, p):
             if ComputationDetails.is_compatible_details(details, p.details):
                 return pcopy
     raise PropertyUnavailableError
Exemplo n.º 5
0
 def get_property_for_molecule(self, molecule, property, details=None):
     for p in self.properties_for_molecules[molecule]:
         if MolecularProperty.is_same_property(property, p):
             if ComputationDetails.is_compatible_details(
                     details, p.details):
                 return p
     props = self.properties[molecule]
     for p in props:
         pcopy = copy(p)
         pcopy.molecule = molecule
         self.properties_for_molecules[molecule].append(pcopy)
         if MolecularProperty.is_same_property(property, p):
             if ComputationDetails.is_compatible_details(
                     details, p.details):
                 return pcopy
     raise PropertyUnavailableError
Exemplo n.º 6
0
 def has_property(self, prop_class, details=None):
     if not self.completed:
         return False
     for p in self.properties:
         if MolecularProperty.is_same_property(p, prop_class) \
                 and (details is None or details.is_subset_of(p.details)):
             return True
     return False
Exemplo n.º 7
0
 def valid_parsers(self):
     valid_parsers = {}
     for property in self.needed_properties:
         for parser in self.property_parsers:
             if parser.compatible_with_details(self.computation.details):
                 if MolecularProperty.is_same_property(
                         property, parser.property):
                     valid_parsers[property.property_type] = parser
                     break
         if not any(
                 MolecularProperty.is_same_property(property, p)
                 for p in valid_parsers):
             raise ComputationUnavailableError(
                 "Could not find a valid parser for {0} in class {1} compatible with details: "
                 "\n{2}".format(property.property_type.__name__,
                                classname(self.__class__),
                                self.computation.details))
     return valid_parsers
Exemplo n.º 8
0
 def has_property_for_molecule(self, molecule, property, details=None, verbose=True):
     if molecule in self.properties:
         props = self.properties[molecule]
         for p in props:
             pcopy = copy(p)
             pcopy.molecule = molecule
             self.properties_for_molecules[molecule].append(pcopy)
             if MolecularProperty.is_same_property(property, p):
                 if ComputationDetails.is_compatible_details(details, p.details):
                     return True
     return False
Exemplo n.º 9
0
 def get_property(self, prop_class, details=None):
     ret_val = None
     if not self.completed:
         return None
     for p in self.properties:
         # TODO figure out which should be a superset of the other
         if MolecularProperty.is_same_property(p, prop_class) and (details is None or details.is_subset_of(p.details)):
             if not ret_val is None and not p.value == ret_val.value:
                 # TODO Raise a more helpful exception class
                 raise RuntimeError("Multiple conflicting values for property " + classname(prop_class))
             ret_val = p
     return ret_val
Exemplo n.º 10
0
 def has_property_for_molecule(self,
                               molecule,
                               property,
                               details=None,
                               verbose=True):
     if molecule in self.properties:
         props = self.properties[molecule]
         for p in props:
             pcopy = copy(p)
             pcopy.molecule = molecule
             self.properties_for_molecules[molecule].append(pcopy)
             if MolecularProperty.is_same_property(property, p):
                 if ComputationDetails.is_compatible_details(
                         details, p.details):
                     return True
     return False
Exemplo n.º 11
0
 def needs_property(self, prop):
     if isinstance(prop, type):
         return any(MolecularProperty.is_same_property(prop, p) for p in self.needed_properties)
     else:
         prop = eval(prop)
         return any(MolecularProperty.is_same_property(prop, p) for p in self.needed_properties)