def __init__(self, CompGraph): self.graph = CompGraph self.graph_info = {} self.send = {} # {(iblock,token):output class} self.requirements = ['pandas'] self.start_time = time.time() self.block_time = 0 self.date = std_datetime_str('date') self.time = std_datetime_str('time') self.InputScript = '' self.output_directory = '.' self.log = []
def write(self, X, main_directory=''): """ Write DataFrame to a comma-seprated-values CSV) file. Parameters ---------- X : array-like This array like input should be a pandas dataframe or should be convertible to a dataframe. main_directory : str, optional (default='') if there is a main directory for entire chemml wrapper project """ try: df = pd.DataFrame(X) except: msg = 'The input `X` must be convertible to a pandas dataframe.' raise TypeError(msg) # create final output dir self.output_directory = os.path.join(main_directory, self.output_directory) if not os.path.exists(self.output_directory): os.makedirs(self.output_directory) # record time if self.record_time: self.file_path = '%s/%s_%s' % (self.output_directory, self.filename, std_datetime_str()) else: self.file_path = '%s/%s' % (self.output_directory, self.filename) # store csv file df.to_csv(self.file_path, index=self.index, header=self.header)
def write(self, X, main_directory=''): """ This function Write an input data X to a file as a string. Parameters ---------- df : array-like The input array main_directory : str, optional (default='') if there is a main directory for entire chemml wrapper project """ X = np.array(X) # create final output dir self.output_directory = os.path.join(main_directory, self.output_directory) if not os.path.exists(self.output_directory): os.makedirs(self.output_directory) if self.record_time: self.file_path = '%s/%s_%s' % (self.output_directory, self.filename, std_datetime_str()) else: self.file_path = '%s/%s' % (self.output_directory, self.filename) # store file f = h5py.File(self.file_path) dst = f.create_dataset('dataset', shape=X.shape, data=X)
def write(self, X, main_directory=''): """ This function Write an input data X to a file as a string. Parameters ---------- X : array-like The input in any format main_directory : str, optional (default='') if there is a main directory for entire chemml wrapper project """ # create final output dir self.output_directory = os.path.join(main_directory, self.output_directory) if not os.path.exists(self.output_directory): os.makedirs(self.output_directory) if self.record_time: self.file_path = '%s/%s_%s' % (self.output_directory, self.filename, std_datetime_str()) else: self.file_path = '%s/%s' % (self.output_directory, self.filename) # store file with open(self.file_path, 'a') as file: file.write('%s\n' % str(X))
def test_std_datetime_str(): s = std_datetime_str(mode='datetime') assert s[-3] == ':' s = std_datetime_str(mode='date') assert s[-3] == '-' s = std_datetime_str(mode='time') assert s[-3] == ':' s = std_datetime_str(mode='datetime_ms') assert s[4] == '-' s = std_datetime_str(mode='time_ms') assert s[2] == ':' with pytest.raises(ValueError): std_datetime_str(mode='hour')
def script_wizard(self, script='new', output_directory='./'): """ The script_wizard is designed to build a Dragon script file. The name and the functionality of this function is the same as available Script wizard in the Dragon Graphic User Interface. Note: All reported nodes are mandatory, except the <EXTERNAL> tag Note: Script for version 7 doesn't support fingerprints block Parameters ---------- script : string, optional (default="new") If "new" start creating a new script from scratch. If you want to load an existing script, pass the filename with drs format. output_directory : string, optional (default = './') the path to the working directory to store output files. dragon : xml element Dragon script in xml format. drs : string Dragon script file name data_path : string The path+name of saved data file in any format. If saveType is 'block' or 'subblock' data_path is just the path to the directory that all data files have been saved. """ self.output_directory = output_directory if not os.path.exists(self.output_directory): os.makedirs(self.output_directory) if script == 'new': if self.version == 6: self.dragon = objectify.Element( "DRAGON", version="%i.0.0" % self.version, script_version="1", generation_date=std_datetime_str('date').replace('-', '/')) OPTIONS = objectify.SubElement(self.dragon, "OPTIONS") OPTIONS.append( objectify.Element("CheckUpdates", value=bool_formatter(self.CheckUpdates))) OPTIONS.append( objectify.Element("SaveLayout", value=bool_formatter(self.SaveLayout))) OPTIONS.append( objectify.Element("ShowWorksheet", value=bool_formatter( self.ShowWorksheet))) OPTIONS.append( objectify.Element("Decimal_Separator", value=self.Decimal_Separator)) OPTIONS.append( objectify.Element("Missing_String", value=self.Missing_String)) OPTIONS.append( objectify.Element("DefaultMolFormat", value=self.DefaultMolFormat)) OPTIONS.append( objectify.Element("HelpBrowser", value=self.HelpBrowser)) OPTIONS.append( objectify.Element("RejectUnusualValence", value=bool_formatter( self.RejectUnusualValence))) OPTIONS.append( objectify.Element("Add2DHydrogens", value=bool_formatter( self.Add2DHydrogens))) OPTIONS.append( objectify.Element("MaxSRforAllCircuit", value=self.MaxSRforAllCircuit)) OPTIONS.append(objectify.Element("MaxSR", value=self.MaxSR)) OPTIONS.append( objectify.Element("MaxSRDetour", value=self.MaxSRDetour)) OPTIONS.append( objectify.Element("MaxAtomWalkPath", value=self.MaxAtomWalkPath)) OPTIONS.append( objectify.Element("LogPathWalk", value=bool_formatter(self.LogPathWalk))) OPTIONS.append( objectify.Element("LogEdge", value=bool_formatter(self.LogEdge))) Weights = objectify.SubElement(OPTIONS, "Weights") for weight in self.Weights: if weight not in [ "Mass", "VdWVolume", "Electronegativity", "Polarizability", "Ionization", "I-State" ]: msg = "'%s' is not a valid weight type." % weight raise ValueError(msg) Weights.append(objectify.Element('weight', name=weight)) OPTIONS.append( objectify.Element("SaveOnlyData", value=bool_formatter(self.SaveOnlyData))) OPTIONS.append( objectify.Element("SaveLabelsOnSeparateFile", value=bool_formatter( self.SaveLabelsOnSeparateFile))) OPTIONS.append( objectify.Element("SaveFormatBlock", value=self.SaveFormatBlock)) OPTIONS.append( objectify.Element("SaveFormatSubBlock", value=self.SaveFormatSubBlock)) OPTIONS.append( objectify.Element("SaveExcludeMisVal", value=bool_formatter( self.SaveExcludeMisVal))) OPTIONS.append( objectify.Element("SaveExcludeAllMisVal", value=bool_formatter( self.SaveExcludeAllMisVal))) OPTIONS.append( objectify.Element("SaveExcludeConst", value=bool_formatter( self.SaveExcludeConst))) OPTIONS.append( objectify.Element("SaveExcludeNearConst", value=bool_formatter( self.SaveExcludeNearConst))) OPTIONS.append( objectify.Element("SaveExcludeStdDev", value=bool_formatter( self.SaveExcludeStdDev))) OPTIONS.append( objectify.Element("SaveStdDevThreshold", value=self.SaveStdDevThreshold)) OPTIONS.append( objectify.Element("SaveExcludeCorrelated", value=bool_formatter( self.SaveExcludeCorrelated))) OPTIONS.append( objectify.Element("SaveCorrThreshold", value=self.SaveCorrThreshold)) OPTIONS.append( objectify.Element( "SaveExclusionOptionsToVariables", value=bool_formatter( self.SaveExclusionOptionsToVariables))) OPTIONS.append( objectify.Element("SaveExcludeMisMolecules", value=bool_formatter( self.SaveExcludeMisMolecules))) OPTIONS.append( objectify.Element("SaveExcludeRejectedMolecules", value=bool_formatter( self.SaveExcludeRejectedMolecules))) DESCRIPTORS = objectify.SubElement(self.dragon, "DESCRIPTORS") for i in self.blocks: if i < 1 or i > 29: msg = "block id must be in range 1 to 29." raise ValueError(msg) DESCRIPTORS.append( objectify.Element('block', id="%i" % i, SelectAll="true")) MOLFILES = objectify.SubElement(self.dragon, "MOLFILES") MOLFILES.append( objectify.Element("molInput", value=self.molInput)) # if self.molInput == "stdin": # if self.molInputFormat not in ['SYBYL', 'MDL', 'HYPERCHEM', 'SMILES', 'MACROMODEL']: # msg = "'%s' is not a valid molInputFormat. Formats:['SYBYL','MDL','HYPERCHEM','SMILES','MACROMODEL']" % self.molInputFormat # raise ValueError(msg) # MOLFILES.append(objectify.Element("molInputFormat", value=self.molInputFormat)) if self.molInput == "file": if isinstance(self.molFile, dict): for f in range(1, len(self.molFile) + 1): MOLFILES.append( objectify.Element( "molFile", value=self.molFile[f]['file'])) elif isinstance(self.molFile, str): MOLFILES.append( objectify.Element("molFile", value=self.molFile)) else: msg = 'Variable molInput can be either a string or a list' raise ValueError(msg) else: msg = "The molInput value must be 'file'. 'stdin' is not supported through ChemML" raise ValueError(msg) OUTPUT = objectify.SubElement(self.dragon, "OUTPUT") OUTPUT.append( objectify.Element("SaveStdOut", value=bool_formatter(self.SaveStdOut))) OUTPUT.append( objectify.Element("SaveProject", value=bool_formatter(self.SaveProject))) if self.SaveProject: OUTPUT.append( objectify.Element("SaveProjectFile", value=self.SaveProjectFile)) OUTPUT.append( objectify.Element("SaveFile", value=bool_formatter(self.SaveFile))) if self.SaveFile: OUTPUT.append( objectify.Element("SaveType", value=self.SaveType) ) # value = "[singlefile/block/subblock]" OUTPUT.append( objectify.Element("SaveFilePath", value=self.output_directory + self.SaveFilePath) ) #Specifies the file name for saving results as a plan text file(s), if the "singlefile" option is set; if "block" or "subblock" are set, specifies the path in which results files will be saved. OUTPUT.append(objectify.Element( "logMode", value=self.logMode)) # value = [none/stderr/file] if self.logMode == "file": OUTPUT.append( objectify.Element("logFile", value=self.output_directory + self.logFile)) if self.external: EXTERNAL = objectify.SubElement(self.dragon, "EXTERNAL") EXTERNAL.append( objectify.Element("fileName", value=self.fileName)) EXTERNAL.append( objectify.Element("delimiter", value=self.delimiter)) EXTERNAL.append( objectify.Element("consecutiveDelimiter", value=bool_formatter( self.consecutiveDelimiter))) EXTERNAL.append( objectify.Element("MissingValue", value=self.MissingValue)) self._save_script() elif self.version == 7: self.dragon = objectify.Element( "DRAGON", version="%i.0.0" % self.version, description="Dragon7 - FP1 - MD5270", script_version="1", generation_date=std_datetime_str('date').replace('-', '/')) OPTIONS = objectify.SubElement(self.dragon, "OPTIONS") OPTIONS.append( objectify.Element("CheckUpdates", value=bool_formatter(self.CheckUpdates))) OPTIONS.append( objectify.Element("PreserveTemporaryProjects", value=bool_formatter( self.PreserveTemporaryProjects))) OPTIONS.append( objectify.Element("SaveLayout", value=bool_formatter(self.SaveLayout))) # OPTIONS.append(objectify.Element("ShowWorksheet", value = bool_formatter(self.ShowWorksheet))) OPTIONS.append( objectify.Element("Decimal_Separator", value=self.Decimal_Separator)) if self.Missing_String == "NaN": self.Missing_String = "na" OPTIONS.append( objectify.Element("Missing_String", value=self.Missing_String)) OPTIONS.append( objectify.Element("DefaultMolFormat", value=self.DefaultMolFormat)) # OPTIONS.append(objectify.Element("HelpBrowser", value = self.HelpBrowser)) OPTIONS.append( objectify.Element("RejectDisconnectedStrucuture", value=bool_formatter( self.RejectDisconnectedStrucuture))) OPTIONS.append( objectify.Element("RetainBiggestFragment", value=bool_formatter( self.RetainBiggestFragment))) OPTIONS.append( objectify.Element("RejectUnusualValence", value=bool_formatter( self.RejectUnusualValence))) OPTIONS.append( objectify.Element("Add2DHydrogens", value=bool_formatter( self.Add2DHydrogens))) OPTIONS.append( objectify.Element( "DisconnectedCalculationOption", value=self.DisconnectedCalculationOption)) OPTIONS.append( objectify.Element("MaxSRforAllCircuit", value=self.MaxSRforAllCircuit)) # OPTIONS.appendm(objectify.Element("MaxSR", value = self.MaxSR)) OPTIONS.append( objectify.Element("MaxSRDetour", value=self.MaxSRDetour)) OPTIONS.append( objectify.Element("MaxAtomWalkPath", value=self.MaxAtomWalkPath)) OPTIONS.append( objectify.Element("RoundCoordinates", value=bool_formatter( self.RoundCoordinates))) OPTIONS.append( objectify.Element("RoundWeights", value=bool_formatter(self.RoundWeights))) OPTIONS.append( objectify.Element("LogPathWalk", value=bool_formatter(self.LogPathWalk))) OPTIONS.append( objectify.Element("LogEdge", value=bool_formatter(self.LogEdge))) Weights = objectify.SubElement(OPTIONS, "Weights") for weight in self.Weights: if weight not in [ "Mass", "VdWVolume", "Electronegativity", "Polarizability", "Ionization", "I-State" ]: msg = "'%s' is not a valid weight type." % weight raise ValueError(msg) Weights.append(objectify.Element('weight', name=weight)) OPTIONS.append( objectify.Element("SaveOnlyData", value=bool_formatter(self.SaveOnlyData))) OPTIONS.append( objectify.Element("SaveLabelsOnSeparateFile", value=bool_formatter( self.SaveLabelsOnSeparateFile))) OPTIONS.append( objectify.Element("SaveFormatBlock", value=self.SaveFormatBlock)) OPTIONS.append( objectify.Element("SaveFormatSubBlock", value=self.SaveFormatSubBlock)) OPTIONS.append( objectify.Element("SaveExcludeMisVal", value=bool_formatter( self.SaveExcludeMisVal))) OPTIONS.append( objectify.Element("SaveExcludeAllMisVal", value=bool_formatter( self.SaveExcludeAllMisVal))) OPTIONS.append( objectify.Element("SaveExcludeConst", value=bool_formatter( self.SaveExcludeConst))) OPTIONS.append( objectify.Element("SaveExcludeNearConst", value=bool_formatter( self.SaveExcludeNearConst))) OPTIONS.append( objectify.Element("SaveExcludeStdDev", value=bool_formatter( self.SaveExcludeStdDev))) OPTIONS.append( objectify.Element("SaveStdDevThreshold", value=self.SaveStdDevThreshold)) OPTIONS.append( objectify.Element("SaveExcludeCorrelated", value=bool_formatter( self.SaveExcludeCorrelated))) OPTIONS.append( objectify.Element("SaveCorrThreshold", value=self.SaveCorrThreshold)) OPTIONS.append( objectify.Element( "SaveExclusionOptionsToVariables", value=bool_formatter( self.SaveExclusionOptionsToVariables))) OPTIONS.append( objectify.Element("SaveExcludeMisMolecules", value=bool_formatter( self.SaveExcludeMisMolecules))) OPTIONS.append( objectify.Element("SaveExcludeRejectedMolecules", value=bool_formatter( self.SaveExcludeRejectedMolecules))) OPTIONS.append( objectify.Element("RoundDescriptorValues", value=bool_formatter( self.RoundDescriptorValues))) DESCRIPTORS = objectify.SubElement(self.dragon, "DESCRIPTORS") for i in self.blocks: if i < 1 or i > 30: msg = "block id must be in range 1 to 30." raise ValueError(msg) DESCRIPTORS.append( objectify.Element('block', id="%i" % i, SelectAll="true")) MOLFILES = objectify.SubElement(self.dragon, "MOLFILES") MOLFILES.append( objectify.Element("molInput", value=self.molInput)) # if self.molInput == "stdin": # if self.molInputFormat not in [ # 'SYBYL', 'MDL', 'HYPERCHEM', 'SMILES', 'CML', 'MACROMODEL' # ]: # msg = "'%s' is not a valid molInputFormat. Formats:['SYBYL','MDL','HYPERCHEM','SMILES','CML','MACROMODEL']" % self.molInputFormat # raise ValueError(msg) # MOLFILES.append(objectify.Element("molInputFormat", value=self.molInputFormat)) if self.molInput == "file": if isinstance(self.molFile, dict): for f in range(1, len(self.molFile) + 1): MOLFILES.append( objectify.Element( "molFile", value=self.molFile[f]['file'])) elif isinstance(self.molFile, str): MOLFILES.append( objectify.Element("molFile", value=self.molFile)) else: msg = 'Variable molFile can be either a string or a list' raise ValueError(msg) else: msg = "The molInput value must be 'file'. 'stdin' is not supported through ChemML" raise ValueError(msg) OUTPUT = objectify.SubElement(self.dragon, "OUTPUT") OUTPUT.append( objectify.Element("knimemode", value=bool_formatter(self.knimemode))) OUTPUT.append( objectify.Element("SaveStdOut", value=bool_formatter(self.SaveStdOut))) OUTPUT.append( objectify.Element("SaveProject", value=bool_formatter(self.SaveProject))) if self.SaveProject: OUTPUT.append( objectify.Element("SaveProjectFile", value=self.SaveProjectFile)) OUTPUT.append( objectify.Element("SaveFile", value=bool_formatter(self.SaveFile))) if self.SaveFile: OUTPUT.append( objectify.Element("SaveType", value=self.SaveType) ) # value = "[singlefile/block/subblock]" OUTPUT.append( objectify.Element("SaveFilePath", value=self.output_directory + self.SaveFilePath) ) #Specifies the file name for saving results as a plan text file(s), if the "singlefile" option is set; if "block" or "subblock" are set, specifies the path in which results files will be saved. OUTPUT.append(objectify.Element( "logMode", value=self.logMode)) # value = [none/stderr/file] if self.logMode == "file": OUTPUT.append( objectify.Element("logFile", value=self.output_directory + self.logFile)) if self.external: EXTERNAL = objectify.SubElement(self.dragon, "EXTERNAL") EXTERNAL.append( objectify.Element("fileName", value=self.fileName)) EXTERNAL.append( objectify.Element("delimiter", value=self.delimiter)) EXTERNAL.append( objectify.Element("consecutiveDelimiter", value=bool_formatter( self.consecutiveDelimiter))) EXTERNAL.append( objectify.Element("MissingValue", value=self.MissingValue)) self._save_script() else: doc = etree.parse(script) self.dragon = etree.tostring(doc) # dragon script : dragon self.dragon = objectify.fromstring(self.dragon) objectify.deannotate(self.dragon) etree.cleanup_namespaces(self.dragon) if self.dragon.attrib['version'][0] not in ['6', '7']: msg = "Dragon script is not labeled to the newest vesions of Dragon, 6 or 7. This may causes some problems." warnings.warn(msg, RuntimeWarning) mandatory_nodes = ['OPTIONS', 'DESCRIPTORS', 'MOLFILES', 'OUTPUT'] reported_nodes = [ element.tag for element in self.dragon.iterchildren() ] if not set(reported_nodes).issuperset(set(mandatory_nodes)): msg = "Dragon script doesn't contain all required nodes, which are:%s" % str( mandatory_nodes) raise ValueError(msg) self.drs = script self.data_path = self.dragon.OUTPUT.SaveFilePath.attrib['value'] return self
def call(self): self.refs = {} for iblock in self.ImpOrder: task = self.cmls[iblock]['task'] parameters = self.cmls[iblock]['parameters'] host = parameters.pop('host') function = parameters.pop('function') start_time = time.time() tmp_str = "======= block#%i: (%s, %s)" % (iblock + 1, host, function) print(tmp_str) tmp_str = "| run ...\n" print(tmp_str) if host == 'sklearn': # check methods legal_functions = [ klass[0] for klass in inspect.getmembers(sklw) ] if function in legal_functions: self.references(host, function) # check references self.Base.graph_info[iblock] = (host, function) cml_interface = [ klass[1] for klass in inspect.getmembers(sklw) if klass[0] == function ][0] cmli = cml_interface(self.Base, parameters, iblock, task, function, host) cmli.run() else: self.references(host, function) # check references self.Base.graph_info[iblock] = (host, function) cml_interface = [ klass[1] for klass in inspect.getmembers(sklw) if klass[0] == 'automatic_run' ][0] cmli = cml_interface(self.Base, parameters, iblock, task, function, host) cmli.run() elif host == 'chemml': # check methods legal_functions = [ klass[0] for klass in inspect.getmembers(cmlw) ] # print("legal_functions: ", legal_functions) if function not in legal_functions: msg = "@function #%i: couldn't find function '%s' in the module '%s' wrapper" % ( iblock, function, host) raise NameError(msg) self.references(host, function) # check references self.Base.graph_info[iblock] = (host, function) cml_interface = [ klass[1] for klass in inspect.getmembers(cmlw) if klass[0] == function ][0] cmli = cml_interface(self.Base, parameters, iblock, task, function, host) cmli.run() elif host == 'pandas': # check methods legal_functions = [ klass[0] for klass in inspect.getmembers(pdw) ] if function not in legal_functions: msg = "@function #%i: couldn't find function '%s' in the module '%s' wrarpper" % ( iblock, function, host) raise NameError(msg) self.references(host, function) # check references self.Base.graph_info[iblock] = (host, function) cml_interface = [ klass[1] for klass in inspect.getmembers(pdw) if klass[0] == function ][0] cmli = cml_interface(self.Base, parameters, iblock, task, function, host) cmli.run() elif host == 'tensorflow': # check methods legal_functions = [ klass[0] for klass in inspect.getmembers(tfw) ] if function not in legal_functions: msg = "@function #%i: couldn't find function '%s' in the module '%s' wrarpper" % ( iblock, function, host) raise NameError(msg) self.references(host, function) # check references self.Base.graph_info[iblock] = (host, function) cml_interface = [ klass[1] for klass in inspect.getmembers(tfw) if klass[0] == function ][0] cmli = cml_interface(self.Base, parameters, iblock, task, function, host) cmli.run() end_time = tot_exec_time_str(start_time) tmp_str = "| ... done!" print(tmp_str) tmp_str = '| ' + end_time print(tmp_str) tmp_str = "=======\n\n" print(tmp_str) self._save_references() tmp_str = "Total " + tot_exec_time_str(self.Base.start_time) print(tmp_str) tmp_str = std_datetime_str() + '\n' print(tmp_str)
def _script_wizard(self, input_mol_list, input_mol_type): """ The script_wizard is designed to build a Dragon script file. The name and the functionality of this function is the same as available Script wizard in the Dragon Graphic User Interface. Note: All reported nodes are mandatory, except the <EXTERNAL> tag Note: Script for version 7 doesn't support fingerprints block Parameters ---------- input_mol_list : list if SMILES, list contains only 1 element -- path to one SMILES file if mol2, list of '.mol2' file paths input_mol_type: str Input molecule type: either 'mol2' or 'smiles' output_directory : string, optional (default = './') the path to the working directory to store output files. """ self.dragon = objectify.Element( "DRAGON", version="%i.0.0" % self.version, description="Dragon7 - FP1 - MD5270", script_version="1", generation_date=std_datetime_str('date').replace('-', '/')) OPTIONS = objectify.SubElement(self.dragon, "OPTIONS") OPTIONS.append( objectify.Element("CheckUpdates", value=bool_formatter(self.CheckUpdates))) OPTIONS.append( objectify.Element("PreserveTemporaryProjects", value=bool_formatter( self.PreserveTemporaryProjects))) OPTIONS.append( objectify.Element("SaveLayout", value=bool_formatter(self.SaveLayout))) # OPTIONS.append(objectify.Element("ShowWorksheet", value = bool_formatter(self.ShowWorksheet))) OPTIONS.append( objectify.Element("Decimal_Separator", value=self.Decimal_Separator)) if self.Missing_String == "NaN": self.Missing_String = "na" OPTIONS.append( objectify.Element("Missing_String", value=self.Missing_String)) OPTIONS.append( objectify.Element("DefaultMolFormat", value=self.DefaultMolFormat)) # OPTIONS.append(objectify.Element("HelpBrowser", value = self.HelpBrowser)) OPTIONS.append( objectify.Element("RejectDisconnectedStrucuture", value=bool_formatter( self.RejectDisconnectedStrucuture))) OPTIONS.append( objectify.Element("RetainBiggestFragment", value=bool_formatter( self.RetainBiggestFragment))) OPTIONS.append( objectify.Element("RejectUnusualValence", value=bool_formatter(self.RejectUnusualValence))) OPTIONS.append( objectify.Element("Add2DHydrogens", value=bool_formatter(self.Add2DHydrogens))) OPTIONS.append( objectify.Element("DisconnectedCalculationOption", value=self.DisconnectedCalculationOption)) OPTIONS.append( objectify.Element("MaxSRforAllCircuit", value=self.MaxSRforAllCircuit)) # OPTIONS.appendm(objectify.Element("MaxSR", value = self.MaxSR)) OPTIONS.append(objectify.Element("MaxSRDetour", value=self.MaxSRDetour)) OPTIONS.append( objectify.Element("MaxAtomWalkPath", value=self.MaxAtomWalkPath)) OPTIONS.append( objectify.Element("RoundCoordinates", value=bool_formatter(self.RoundCoordinates))) OPTIONS.append( objectify.Element("RoundWeights", value=bool_formatter(self.RoundWeights))) OPTIONS.append( objectify.Element("LogPathWalk", value=bool_formatter(self.LogPathWalk))) OPTIONS.append( objectify.Element("LogEdge", value=bool_formatter(self.LogEdge))) Weights = objectify.SubElement(OPTIONS, "Weights") for weight in self.Weights: if weight not in [ "Mass", "VdWVolume", "Electronegativity", "Polarizability", "Ionization", "I-State" ]: msg = "'%s' is not a valid weight type." % weight raise ValueError(msg) Weights.append(objectify.Element('weight', name=weight)) OPTIONS.append( objectify.Element("SaveOnlyData", value=bool_formatter(self.SaveOnlyData))) OPTIONS.append( objectify.Element("SaveLabelsOnSeparateFile", value=bool_formatter( self.SaveLabelsOnSeparateFile))) OPTIONS.append( objectify.Element("SaveFormatBlock", value=self.SaveFormatBlock)) OPTIONS.append( objectify.Element("SaveFormatSubBlock", value=self.SaveFormatSubBlock)) OPTIONS.append( objectify.Element("SaveExcludeMisVal", value=bool_formatter(self.SaveExcludeMisVal))) OPTIONS.append( objectify.Element("SaveExcludeAllMisVal", value=bool_formatter(self.SaveExcludeAllMisVal))) OPTIONS.append( objectify.Element("SaveExcludeConst", value=bool_formatter(self.SaveExcludeConst))) OPTIONS.append( objectify.Element("SaveExcludeNearConst", value=bool_formatter(self.SaveExcludeNearConst))) OPTIONS.append( objectify.Element("SaveExcludeStdDev", value=bool_formatter(self.SaveExcludeStdDev))) OPTIONS.append( objectify.Element("SaveStdDevThreshold", value=self.SaveStdDevThreshold)) OPTIONS.append( objectify.Element("SaveExcludeCorrelated", value=bool_formatter( self.SaveExcludeCorrelated))) OPTIONS.append( objectify.Element("SaveCorrThreshold", value=self.SaveCorrThreshold)) OPTIONS.append( objectify.Element("SaveExclusionOptionsToVariables", value=bool_formatter( self.SaveExclusionOptionsToVariables))) OPTIONS.append( objectify.Element("SaveExcludeMisMolecules", value=bool_formatter( self.SaveExcludeMisMolecules))) OPTIONS.append( objectify.Element("SaveExcludeRejectedMolecules", value=bool_formatter( self.SaveExcludeRejectedMolecules))) OPTIONS.append( objectify.Element("RoundDescriptorValues", value=bool_formatter( self.RoundDescriptorValues))) DESCRIPTORS = objectify.SubElement(self.dragon, "DESCRIPTORS") for i in self.blocks: if i < 1 or i > 30: msg = "block id must be in range 1 to 30." raise ValueError(msg) DESCRIPTORS.append( objectify.Element('block', id="%i" % i, SelectAll="true")) MOLFILES = objectify.SubElement(self.dragon, "MOLFILES") MOLFILES.append(objectify.Element("molInput", value="file")) # if self.molInput == "stdin": # if self.molInputFormat not in [ # 'SYBYL', 'MDL', 'HYPERCHEM', 'SMILES', 'CML', 'MACROMODEL' # ]: # msg = "'%s' is not a valid molInputFormat. Formats:['SYBYL','MDL','HYPERCHEM','SMILES','CML','MACROMODEL']" % self.molInputFormat # raise ValueError(msg) # MOLFILES.append(objectify.Element("molInputFormat", value=self.molInputFormat)) if input_mol_type == 'mol2': for mol2 in input_mol_list: MOLFILES.append(objectify.Element("molFile", value=mol2)) else: MOLFILES.append( objectify.Element("molFile", value=input_mol_list[0])) # if isinstance(self.molFile, dict): # for f in range(1, len(self.molFile) + 1): # if os.path.exists(self.molFile[f]['file']): # MOLFILES.append(objectify.Element("molFile", value=self.molFile[f]['file'])) # else: # msg = "file not found at "+ self.molFile[f]['file'] # raise FileNotFoundError(msg) # elif isinstance(self.molFile, str): # MOLFILES.append(objectify.Element("molFile", value=self.molFile)) # else: # msg = 'Variable molFile can be either a string or a list' # raise ValueError(msg) OUTPUT = objectify.SubElement(self.dragon, "OUTPUT") OUTPUT.append( objectify.Element("knimemode", value=bool_formatter(self.knimemode))) OUTPUT.append( objectify.Element("SaveStdOut", value=bool_formatter(self.SaveStdOut))) OUTPUT.append( objectify.Element("SaveProject", value=bool_formatter(self.SaveProject))) if self.SaveProject: OUTPUT.append( objectify.Element("SaveProjectFile", value=self.SaveProjectFile)) OUTPUT.append( objectify.Element("SaveFile", value=bool_formatter(self.SaveFile))) if self.SaveFile: OUTPUT.append(objectify.Element( "SaveType", value=self.SaveType)) # value = "[singlefile/block/subblock]" OUTPUT.append( objectify.Element("SaveFilePath", value=self.output_directory + self.SaveFilePath) ) #Specifies the file name for saving results as a plan text file(s), if the "singlefile" option is set; if "block" or "subblock" are set, specifies the path in which results files will be saved. OUTPUT.append(objectify.Element( "logMode", value=self.logMode)) # value = [none/stderr/file] if self.logMode == "file": OUTPUT.append( objectify.Element("logFile", value=self.output_directory + self.logFile)) if self.external: EXTERNAL = objectify.SubElement(self.dragon, "EXTERNAL") EXTERNAL.append(objectify.Element("fileName", value=self.fileName)) EXTERNAL.append( objectify.Element("delimiter", value=self.delimiter)) EXTERNAL.append( objectify.Element("consecutiveDelimiter", value=bool_formatter( self.consecutiveDelimiter))) EXTERNAL.append( objectify.Element("MissingValue", value=self.MissingValue)) # objectify.deannotate(self.dragon) etree.cleanup_namespaces(self.dragon) self.drs_name = 'Dragon_script.drs' with open(os.path.join(self.output_directory, self.drs_name), 'w') as outfile: outfile.write( etree.tostring(self.dragon, pretty_print=True).decode()) self.data_path = self.dragon.OUTPUT.SaveFilePath.attrib['value'] return self