def __parse_score_weights_penalties(self, line, param_name): values = [line.split()[1], line.split()[2]] if len(values) != 2 : raise ConfigError(str(param_name).upper()+" parameter you must provide 2 values") if values[0].upper() == "X" or values[1].upper() == "X": return 1 if values[0].isalpha() or values[1].isalpha(): raise ConfigError(str(param_name).upper()+"must be DIGID not alfanumeric value") elif float(values[0]) >= 0 and float(values[1]) >=0 : setattr(self, param_name, [float(values[0]), float(values[1])]) else: raise ConfigError(str(param_name).upper()+"value must be positive value!") if param_name == "freespace_penalty": if float(values[0]) == 0. and float(values[1]) == 0: self.is_freespace_defined = False else: self.is_freespace_defined = True if param_name == "density_penalty": if float(values[0]) == 0. and float(values[1]) == 0: self.is_density_defined = False else: self.is_density_defined = True if param_name == "chi2_penalty": if float(values[0]) == 0. and float(values[1]) == 0: self.is_chi2_defined = False else: self.is_chi2_defined = True if param_name == "rg_penalty": if float(values[0]) == 0. and float(values[1]) == 0: self.is_rg_penalty_defined = False else: self.is_rg_penalty_defined = True
def __parse_rot_angle(self, line): """ """ maxrot = line.split()[1] if maxrot.upper() == "X": return 1 if maxrot.isalpha() : raise ConfigError("MAXROT must be DIGID not alfanumeric value") if -360.0 > float(maxrot) > 360.: raise ConfigError("Rotation angle cannot be larger than 360 degrees or smaller than -360") else: self.max_rot_angle = float(maxrot)
def __parse_kvol(self, line): """ """ kvol = line.split()[1] if kvol.isalpha() : raise ConfigError("KVOL must be DIGIDS not alfanumeric value") if kvol.upper() == "X": return 1 else: if (float(kvol) > 10 or float(kvol) < 0): raise ConfigError("Volume you provided is not in the range from 0 to 10!%s "%(kvol)) elif float(kvol) == 0: raise ConfigError("Volume must be larger than 0!") self.kvol = float(kvol)
def __parse_reheating_param(self, line): line = line.split() reheat = line[1] reheat_rejections = line[2] if reheat.upper() not in ["TRUE", "FALSE"]: raise ConfigError("Reheat is of value True or False") if reheat_rejections.isalpha(): raise ConfigError("Rejection must be float value") elif reheat.upper() == "TRUE" and float(reheat_rejections) > self.simul_steps : raise ConfigError ("Rejection frequency cannot be larger than number of simulation steps") elif float(reheat_rejections) <= 0 : raise ConfigError ("Rejection frequency cannot be lower than 0") if reheat.upper() == "TRUE": self.reheat = True else: self.reheat = False self.reheat_rejections = float(reheat_rejections)
def __parse_outsteps(self, line): """ """ out_steps = [line.split()[1], line.split()[2]] if len(out_steps) != 2 : raise ConfigError("for OUTSTEPS parameter you must provide 2 values") if (out_steps[0].upper() == "X" and out_steps[1].upper() == "X") \ or (out_steps[0].upper() == "FIRST" and out_steps[1].upper() == "LAST"): self.out_steps.append(1) self.out_steps.append(self.simul_steps-1) elif float(out_steps[1]) > self.simul_steps: raise ConfigError("Steps value cannot be larger than number of simulations!") elif (out_steps[0] > 0 and out_steps[1] > 0): self.out_steps = [int(line.split()[1]), int(line.split()[2])] else: raise ConfigError("OutSteps value must be positive value!")
def __parse_mutation_frequencies(self, line, param_name): value = line.split()[1] floatValue = float(value) if value.upper() == "X": return 1 #mutation_name = param_name.split("_")[0] mutation_name = param_name.replace("_freq","") if mutation_name == "simul_dd": mutation_name = "SimulateDisorder" if floatValue == 0: self.disabled_mutations.append(mutation_name) if value.isalpha() : raise ConfigError(str(param_name)+"must be DIGID not alfanumeric value") elif 0. <= floatValue <= 1. : setattr(self, param_name, floatValue) else: raise ConfigError("Frequency of"+str(param_name).upper()+"must be defined in range from 0 to 1") return {mutation_name: floatValue}
def __set_outsave_mode(self): """ """ if self.simul_steps == 0: pass elif self.niter > self.simul_steps: raise ConfigError("Steps to write cannot be larger than number of simulation steps!") #self.out_steps = [] if self.out_steps and self.niter and self.write_eachbetter: raise ConfigError("You can select only one of output save methods either WRITE_N_ITER or or WRITE_EACHBETTER or OUT_STEPS") if self.out_steps : self.save_res_mode = "outsteps" elif self.write_eachbetter : self.save_res_mode = "eachbetter" elif self.niter : self.save_res_mode = "niter"
def __parse_positive_params(self, line, param_name, type = "float"): """ """ value = line.split()[1] if value.upper() == "X": return 1 if value.isalpha() : raise ConfigError(str(param_name)+"must be DIGID not alfanumeric value") if not param_name == "threshold": try: float(value) < 0 except: raise ConfigError(str(param_name).upper()+"must be positive value! Use dots for float numbers.") if type == "float": setattr(self, param_name, float(value)) if type == "int": setattr(self, param_name, int(value))
def __parse_param_value(self, line, param_name, list_of_values): """ """ value = line.split()[1] found = False if value.upper() == "X" : return 1 if value.isdigit() : raise ConfigError(str(param_name).upper()+"must be alfanumeric not DIGIT value") for val in list_of_values: if value.lower() == val.lower(): found = True break if found == False: raise ConfigError(str(param_name).upper()+" has only possible values "+"".join(list_of_values) ) if param_name == "simmethod" and value.upper() == "X": setattr(self,param_name, "simulatedannealing") else: setattr(self,param_name, value.lower())
def __parse_scaling(self, line, param_name, counter): """ """ if counter == 3: values = [float(line.split()[1]), float(line.split()[2]), float(line.split()[3])] elif counter == 2: values = [float(line.split()[1]), float(line.split()[2])] percentValues = [] for val in values: if str(val).isalpha(): raise ConfigError(param_name.upper()+"must be DIGITS not alfanumeric value") elif 100 < val < 0: raise ConfigError(param_name.upper()+"must be from range 0 to 100") percentValues.append(val/100.0) setattr(self, param_name, percentValues) return percentValues
def __check_shape_descriptors(self): """ """ if self.shapedesc: if self.kvol_given == False and self.threshold_given == False and self.shapedesc == "map": raise ConfigError("You must provide kvol or threshold value when you provide density map as input") if self.kvol_given and self.threshold_given: raise ConfigError("Please provide only one of these two parameters: KVOL or THRESHOLD!") if self.threshold != None: self.kvol = None if self.is_freespace_defined == False: self.freespace_penalty = [0.,0.] if self.is_density_defined == False: self.density_penalty = [0.,0.] if self.density_penalty[0] != 0. and self.freespace_penalty[0] != 0.: print ConfigError("Scoring function will penalyze shape filling twice since you defined two parameters: DENSITY and MAP_FREESPACE!") logfile.write_file("Scoring function will penalyze shape filling twice since you defined two parameters: DENSITY and MAP_FREESPACE!\n") if self.simbox > 10: raise ConfigError("The size of the system you want to use is very large. Max simbox value is 10") #when no file with density map or ab initio model was provided but density filling or mapspace weights were provided if self.shapedesc == False and self.is_density_defined == True: #and (self.density_penalty[0] != 0): raise ConfigError("Map filling cannot be calculated when no shape descriptor was provided!\n") logfile.write_file("Map filling cannot be calculated when no shape descriptor was provided!") #print "@@@@@@", self.shapedesc, self.is_freespace_defined if self.shapedesc == False and self.is_freespace_defined == True: #(self.freespace_penalty[0] != 0): #print "****", self.shapedesc, self.is_freespace_defined raise ConfigError("Map filling cannot be calculated when no shape descriptor was provided!") logfile.write_file("Map filling cannot be calculated when no shape descriptor was provided!\n") if self.shapedesc == "map" or self.shapedesc == "saxs": self.shapedesc = True if self.is_chi2_defined == True or self.is_rg_penalty_defined == True: if not self.curve: raise ConfigError("To verify discrepancy with SAXS/SANS curves you must provide .dat file!") else: self.crysol_outfile = open("crysol_summary.txt", "w") if self.representation == "sphere" and self.restraints_penalty[0] == 0 and self.restraints_penalty[1] == 0: raise ConfigError ("To validate clashes between spheres PyRy3D calculates violation of distances betweeen\ spheres centres. To allow this option penalty for RESTRAINTS must be different than 0 0") if self.identify_disorders == False and self.simul_dd_freq != 0.: raise ConfigError ("You must allow PyRy3D to identify disorders to use simulate disorder mutation. Please set IDENTIFY_DISORDER parameter into True or disable simulate disorder mutation by setting SIMUL_DD_FREQ to 0 0 values")
def __check_save_structnr(self, params): """ """ for param in params: if self.simul_steps == 0: pass elif getattr(self, param) > self.simul_steps: print getattr(self, param) raise ConfigError(str(param).upper()+" value cannot be larger than number of simulations!")
def __parse_bool_param(self,line, param_name): val = line.split()[1] if val.upper() not in ["TRUE", "FALSE"]: raise ConfigError('%s can be "True" or "False"'%(param_name.upper())) else: if val.upper() == "TRUE": val = True else: val=False setattr(self, param_name, val)
def __parse_trans_vector(self, line): """ """ trans_vec = [line.split()[1], line.split()[2], line.split()[3]] if len(trans_vec) != 3 : raise ConfigError("for MAXTRANS parameter you must provide 3 values") if trans_vec[0].upper() == "X" or trans_vec[1].upper() == "X" or trans_vec[2].upper() == "X": return 1 elif trans_vec[0].isalpha() or trans_vec[1].isalpha() or trans_vec[2].isalpha() : raise ConfigError("MAXTRANS must be DIGIDS not alfanumeric value") self.max_trans_vec = [float(trans_vec[0]), float(trans_vec[1]), float(trans_vec[2])]
def __parse_movestate(self, line): """ """ chain_name = line.split()[1] move_state = line.split()[2] if move_state.lower() == "fixed" or move_state.lower() == "movable": pass else: raise ConfigError("unknown state %s"%(move_state)) move_state = Movable(chain_name, line) #print "@@@@@@@@@@2", move_state self.movable.append(move_state)
def __check_mut_freq_correctness(self): """ """ sumpar = float(self.rotation_freq + self.rotation_cov_freq + self.translation_freq + self.exchange_freq + self.exchangeandsample_freq\ + self.simul_dd_freq + self.translation_all_freq + self.rotation_all_freq \ + self.rotation_whole_freq) if round(sumpar,1) > float(1.0): raise ConfigError("Frequencies of mutations must sum up to 1. You provided %s"%(sumpar)) if round(sumpar,1) < float(1.0): self.rotation_freq = self.rotation_freq/sumpar *1.0 self.rotation_cov_freq = self.rotation_cov_freq/sumpar *1.0 self.translation_freq = self.translation_freq/sumpar *1.0 self.exchange_freq = self.exchange_freq/sumpar *1.0 self.exchangesample_freq = self.exchangeandsample_freq/sumpar *1.0 self.simul_dd_freq = self.simul_dd_freq/sumpar *1.0 self.translation_all_freq = self.translation_all_freq/sumpar *1.0 self.rotation_all_freq = self.rotation_all_freq/sumpar *1.0 self.rotation_whole_freq = self.rotation_whole_freq/sumpar *1.0
def __parse_covalent_links(self, line): try: linked_components = eval(line.split()[2]) #.replace("[","").replace("]","").replace(",","")) except ConfigError: print "Please provide correct format for COVALENT_BONDS parameter in configuration file" #linked_components = line.split()[2].replace("[","").replace("]","").replace(",","") component = line.split()[1] if component not in self.linked_components.keys(): for el in linked_components: if el == component: raise ConfigError("Component %s cannot be bound with %s "%(component, el)) #self.linked_components[component] = linked_components at1 = eval(line.split()[3]) at2 = eval(line.split()[4]) covbond = CovalentBond(linked_components, at1, at2) if self.linked_components.has_key(component): self.linked_components[component].append(covbond) else: self.linked_components[component] = [covbond]
def __check_atoms(self, atom): if len(atom) != 2: raise ConfigError("You haven't provided enough information about covalent bonds atoms") if not str(atom[0]).isdigit(): raise ConfigError ("Residue number should be number not string") if not str(atom[1]).isalpha(): raise ConfigError ("Atom name must be string, not number")
def __check_mutual_clashes_options(self): if self.required_clashes_penalty == True and self.required_clashes_penalty_allatoms == True: raise ConfigError("Only one option can be applied CLASHES or CLASHES_ALLATOMS. \ Please change values into 0 for one of the parameters or comment one option in configuarion file")