def loadEntry(self, index, label, molecule, thermo, reference=None, referenceType='', shortDesc='', longDesc='', ): molecule = Molecule().fromAdjacencyList(molecule) # Internal checks for adding entry to the thermo library if label in self.entries.keys(): raise DatabaseError('Found a duplicate molecule with label {0} in the thermo library. Please correct your library.'.format(label)) for entry in self.entries.values(): if molecule.isIsomorphic(entry.item): raise DatabaseError('Adjacency list of {0} matches that of existing molecule {1} in thermo library. Please correct your library.'.format(label, entry.label)) self.entries[label] = Entry( index = index, label = label, item = molecule, data = thermo, reference = reference, referenceType = referenceType, shortDesc = shortDesc, longDesc = longDesc.strip(), )
def getSolventStructure(self, solvent_name): try: solventStructure = self.libraries['solvent'].getSolventStructure( solvent_name) except: raise DatabaseError( 'Solvent {0!r} not found in database'.format(solvent_name)) return solventStructure
def __addGroupThermoData(self, thermoData, database, molecule, atom): """ Determine the group additivity thermodynamic data for the atom `atom` in the structure `structure`, and add it to the existing thermo data `thermoData`. """ node0 = database.descendTree(molecule, atom, None) if node0 is None: raise KeyError('Node not found in database.') # It's possible (and allowed) that items in the tree may not be in the # library, in which case we need to fall up the tree until we find an # ancestor that has an entry in the library node = node0 while node.data is None and node is not None: node = node.parent if node is None: raise DatabaseError( 'Unable to determine thermo parameters for {0}: no library entries for {1} or any of its ancestors.' .format(molecule, node0)) data = node.data comment = node.label while isinstance(data, basestring) and data is not None: for entry in database.entries.values(): if entry.label == data: data = entry.data comment = entry.label break data.comment = '{0}({1})'.format(database.label, comment) # This code prints the hierarchy of the found node; useful for debugging # result = '' # while node is not None: # result = ' -> ' + node.label + result # node = node.parent # print result[4:] if thermoData is None: return data else: return self.__addThermoData(thermoData, data)
def saveEntry(f, entry): """ Write a Pythonic string representation of the given `entry` in the solvation database to the file object `f`. """ f.write('entry(\n') f.write(' index = {0:d},\n'.format(entry.index)) f.write(' label = "{0}",\n'.format(entry.label)) if isinstance(entry.item, Species): if Molecule(SMILES=entry.item.molecule[0].toSMILES()).isIsomorphic(entry.item.molecule[0]): # The SMILES representation accurately describes the molecule, so we can save it that way. f.write(' molecule = "{0}",\n'.format(entry.item.molecule[0].toSMILES())) else: f.write(' molecule = \n') f.write('"""\n') f.write(entry.item.toAdjacencyList(removeH=False)) f.write('""",\n') elif isinstance(entry.item, Group): f.write(' group = \n') f.write('"""\n') f.write(entry.item.toAdjacencyList()) f.write('""",\n') elif entry.item is not None: f.write(' group = "{0}",\n'.format(entry.item)) if isinstance(entry.data, SoluteData): f.write(' solute = SoluteData(\n') f.write(' S = {0!r},\n'.format(entry.data.S)) f.write(' B = {0!r},\n'.format(entry.data.B)) f.write(' E = {0!r},\n'.format(entry.data.E)) f.write(' L = {0!r},\n'.format(entry.data.L)) f.write(' A = {0!r},\n'.format(entry.data.A)) if entry.data.V is not None: f.write(' V = {0!r},\n'.format(entry.data.V)) f.write(' ),\n') elif isinstance(entry.data, SolventData): f.write(' solvent = SolventData(\n') f.write(' s_g = {0!r},\n'.format(entry.data.s_g)) f.write(' b_g = {0!r},\n'.format(entry.data.b_g)) f.write(' e_g = {0!r},\n'.format(entry.data.e_g)) f.write(' l_g = {0!r},\n'.format(entry.data.l_g)) f.write(' a_g = {0!r},\n'.format(entry.data.a_g)) f.write(' c_g = {0!r},\n'.format(entry.data.c_g)) f.write(' s_h = {0!r},\n'.format(entry.data.s_h)) f.write(' b_h = {0!r},\n'.format(entry.data.b_h)) f.write(' e_h = {0!r},\n'.format(entry.data.e_h)) f.write(' l_h = {0!r},\n'.format(entry.data.l_h)) f.write(' a_h = {0!r},\n'.format(entry.data.a_h)) f.write(' c_h = {0!r},\n'.format(entry.data.c_h)) f.write(' A = {0!r},\n'.format(entry.data.A)) f.write(' B = {0!r},\n'.format(entry.data.B)) f.write(' C = {0!r},\n'.format(entry.data.C)) f.write(' D = {0!r},\n'.format(entry.data.D)) f.write(' E = {0!r},\n'.format(entry.data.E)) f.write(' alpha = {0!r},\n'.format(entry.data.alpha)) f.write(' beta = {0!r},\n'.format(entry.data.beta)) f.write(' eps = {0!r},\n'.format(entry.data.eps)) f.write(' ),\n') elif entry.data is None: f.write(' solute = None,\n') else: raise DatabaseError("Not sure how to save {0!r}".format(entry.data)) f.write(' shortDesc = u"""') try: f.write(entry.shortDesc.encode('utf-8')) except: f.write(entry.shortDesc.strip().encode('ascii', 'ignore')+ "\n") f.write('""",\n') f.write(' longDesc = \n') f.write('u"""\n') try: f.write(entry.longDesc.strip().encode('utf-8') + "\n") except: f.write(entry.longDesc.strip().encode('ascii', 'ignore')+ "\n") f.write('""",\n') f.write(')\n\n')
def saveEntry(f, entry): """ Write a Pythonic string representation of the given `entry` in the transport database to the file object `f`. """ f.write('entry(\n') f.write(' index = {0:d},\n'.format(entry.index)) f.write(' label = "{0}",\n'.format(entry.label)) if isinstance(entry.item, Molecule): f.write(' molecule = \n') f.write('"""\n') f.write(entry.item.toAdjacencyList(removeH=False)) f.write('""",\n') elif isinstance(entry.item, Group): f.write(' group = \n') f.write('"""\n') f.write(entry.item.toAdjacencyList()) f.write('""",\n') else: f.write(' group = "{0}",\n'.format(entry.item)) if isinstance(entry.data, CriticalPointGroupContribution): f.write(' transportGroup = CriticalPointGroupContribution(\n') f.write(' Tc = {0!r},\n'.format(entry.data.Tc)) f.write(' Pc = {0!r},\n'.format(entry.data.Pc)) f.write(' Vc = {0!r},\n'.format(entry.data.Vc)) f.write(' Tb = {0!r},\n'.format(entry.data.Tb)) f.write(' structureIndex = {0!r},\n'.format(entry.data.structureIndex)) f.write(' ),\n') elif entry.data is None: f.write(' transportGroup = None,\n') elif isinstance(entry.data, TransportData): f.write(' transport = TransportData(\n') f.write(' shapeIndex = {0!r},\n'.format(entry.data.shapeIndex)) f.write(' epsilon = {0!r},\n'.format(entry.data.epsilon)) f.write(' sigma = {0!r},\n'.format(entry.data.sigma)) f.write(' dipoleMoment = {0!r},\n'.format(entry.data.dipoleMoment)) f.write(' polarizability = {0!r},\n'.format(entry.data.polarizability)) f.write(' rotrelaxcollnum = {0!r},\n'.format(entry.data.rotrelaxcollnum)) f.write(' ),\n') else: raise DatabaseError("Not sure how to save {0!r}".format(entry.data)) f.write(' shortDesc = u"""') try: f.write(entry.shortDesc.encode('utf-8')) except: f.write(entry.shortDesc.strip().encode('ascii', 'ignore')) f.write('""",\n') if entry.longDesc: f.write(' longDesc = \n') f.write('u"""\n') try: f.write(entry.longDesc.strip().encode('utf-8') + "\n") except: f.write(entry.longDesc.strip().encode('ascii', 'ignore')+ "\n") f.write('""",\n') else: f.write(' longDesc = u"""""",\n') f.write(')\n\n')