From d0c6234fed7d45227fcf9309cb6dc0854d17e647 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Sun, 28 Feb 2016 16:00:15 +0100 Subject: physchem calculation and storage in compouds --- lib/compound.rb | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'lib/compound.rb') diff --git a/lib/compound.rb b/lib/compound.rb index 4ea4db4..8c11831 100644 --- a/lib/compound.rb +++ b/lib/compound.rb @@ -17,7 +17,6 @@ module OpenTox field :smiles, type: String field :inchikey, type: String field :names, type: Array - #field :warnings, type: Array, default: [] field :cid, type: String field :chemblid, type: String field :png_id, type: BSON::ObjectId @@ -88,17 +87,26 @@ module OpenTox fingerprints[type] end - def physchem descriptor_ids - calculated_descriptor_ids = self[:physchem_descriptors].keys - p names - new = UNIQUEDESCRIPTORS-names - p new - d = self.physchem(self, new) - #p d - #self[:physchem_descriptors].merge! d - self.update_attribute(:physchem_descriptors, self[:physchem_descriptors].merge(d)) + def physchem descriptors=PhysChem.openbabel_descriptors + # TODO: speedup java descriptors + calculated_ids = physchem_descriptors.keys + # BSON::ObjectId instances are not allowed as keys in a BSON document. + new_ids = descriptors.collect{|d| d.id.to_s} - calculated_ids + descs = {} + algos = {} + new_ids.each do |id| + descriptor = PhysChem.find id + descs[[descriptor.library, descriptor.descriptor]] = descriptor + algos[descriptor.name] = descriptor + end + # avoid recalculating Cdk features with multiple values + descs.keys.uniq.each do |k| + descs[k].send(k[0].downcase,k[1],self).each do |n,v| + physchem_descriptors[algos[n].id.to_s] = v # BSON::ObjectId instances are not allowed as keys in a BSON document. + end + end save - self[:physchem_descriptors] + physchem_descriptors end # Create a compound from smiles string -- cgit v1.2.3