def on_process(self): print('process') # print(self.ui.layout.rowCount()) layout = self.ui.externalLayout.itemAt(0) print(layout) self.read_params() la = self.la dla = self.dla mu = self.mu dmu = self.dmu tmax = self.tmax mT1, dT1, mT2, dT2 = calculate_params(la, dla, mu, dmu) model = modeller.Model(mT1, dT1, mT2, dT2, 1, 1, 0) print('start') ro = la / mu avg_queue_size, avg_queue_time, processed_requests = model.time_based_modellingg(tmax, 0.001) result = f'Расчетная загрузка системы: {ro}\n' \ f'Среднее количество заявок в системе: {avg_queue_size}\n' \ f'Среднее время ожидания: {avg_queue_time}\n' \ f'Обработано заявок: {processed_requests}' QMessageBox.information(self, 'Result', result) self.set_free_point()
def test_disulfide(self): """Test handling of disulfide bonds""" mlib = self.get_all_libraries() bsep = mdt.features.AtomBondSeparation(mlib, bins=mdt.uniform_bins( 20, 0, 1.0)) bsep_ss = mdt.features.AtomBondSeparation(mlib, bins=mdt.uniform_bins( 20, 0, 1.0), disulfide=True) env = self.get_environ() mdl = modeller.Model(env) mdl.build_sequence('CC') # When SG-SG distance is small enough, an extra bond # (separation feature = 1) should be detected, but only with # disulfide=True for (dist, num) in [(2.6, 11.0), (2.4, 12.0)]: sg1 = mdl.residues[0].atoms['SG'] sg2 = mdl.residues[1].atoms['SG'] sg1.x = sg1.y = sg1.z = 0. sg2.x = sg2.y = 0. sg2.z = dist a = modeller.Alignment(env) a.append_model(mdl, atom_files='test', align_codes='test') m = mdt.Table(mlib, features=bsep) m.add_alignment(a, residue_span_range=(-999, 0, 0, 999)) self.assertEqual(m[1], 11.0) m2 = mdt.Table(mlib, features=bsep_ss) m2.add_alignment(a, residue_span_range=(-999, 0, 0, 999)) self.assertEqual(m2[1], num)
def loadStage(self, **kwargs): verbose = kwargs.get('verbose', False) stageID = kwargs.get('stage', None) if not self.window: print('No window has been loaded!') elif stageID == None: print('No stage argument sent!') else: stage = utils.getStage(stageID, verbose=verbose) for y in range(len(stage["map"])): for z in range(len(stage["map"][y])): for x in range(len(stage["map"][y][z])): if self.blockList[stage["map"][y][z] [x]] == self.blockList[0]: continue self.window.addModel( modeller.Model( textures=utils.getBlockTexture( stage["map"][y][z][x]), origin=[ x * stage['scale'], y * stage['scale'], z * stage['scale'] ], Figure=self.blockList[stage["map"][y][z] [x]]['model'], size=stage['scale'] * self.blockList[stage["map"][y][z][x]]['size']))
def get_sas(pdb, probe): import modeller # Read the PDB file env = modeller.Environ() mdl = modeller.Model(env) mdl.read(file=pdb) # Calculate atomic accessibilities (in Biso) with appropriate probe_radius myedat = modeller.EnergyData() myedat.radii_factor = 1.6 mdl.write_data(edat=myedat, output='PSA ATOMIC_SOL', psa_integration_step=0.05, probe_radius=probe) mdl.write(file=pdb.rsplit('.', 1)[0] + '.sas') # read SAS with open('%s.sas' % (pdb.rsplit('.', 1)[0], )) as data: D = data.readlines() Sas = {} for d in D: d = d.strip() if d[:4] == 'ATOM': atom, res, resid, cid = d[12:16], d[17:20], int(d[22:26]), d[21] if cid == ' ': cid = 'A' Sas[(atom, res, resid, cid)] = float(d[60:66]) return Sas
def build_models(self, config): base_config = copy.copy(config.modelling_configuration) base_config['model'] = config.model for dataset, timespan in zip(config.datasets, config.time_span): model_config = base_config model_config['dataset'] = dataset model_config['time_span'] = timespan self.models.append(modeller.Model(model_config))
def test_detect_invalid_residue_types_ok(self): """Test _detect_invalid_residue_types() with OK sequence""" with utils.temporary_directory() as tmpdir: fname = os.path.join(tmpdir, 'test.pdb') with open(fname, 'w') as fh: fh.write(pdb_line + '\n') e = modeller.Environ() m = modeller.Model(e, file=fname) cleaning._detect_invalid_residue_types(m)
def _parse_parameters(self): try: ui = self.ui a = float(ui.lineEdit_generator_a.text()) b = float(ui.lineEdit_generator_b.text()) m = float(ui.lineEdit_servicemachine_m.text()) d = float(ui.lineEdit_servicemachine_d.text()) req_count = int(ui.lineEdit_request_count.text()) reenter_prob = float(ui.lineEdit_reenter_probability.text()) delta_t = float(ui.lineEdit_deltat.text()) modelT = modeller.Model(delta_t, req_count, reenter_prob) results1 = modelT.time_based_modelling(a, b, m, d) modelEvent = modeller.Model(delta_t, req_count, reenter_prob) results2 = modelEvent.event_based_modelling(a, b, m, d) self._show_results(results1, results2) except ValueError: QMessageBox.warning(self, 'Ошибка', 'Ошибка в данных!') except Exception as e: QMessageBox.critical(self, 'Ошибка', e)
def build_mdt_from_sequence(self, mlib, features, seq, **keys): """Build a simple test MDT for a given sequence""" env = self.get_environ() mdl = modeller.Model(env) mdl.build_sequence(seq) m = mdt.Table(mlib, features=features) a = modeller.Alignment(env) a.append_model(mdl, atom_files='test', align_codes='test') m.add_alignment(a, **keys) return m
def get_test_mdt(self, mlib, features): env = self.get_environ() mdl = modeller.Model(env) mdl.build_sequence('C') m = mdt.Table(mlib, features=features) a = modeller.Alignment(env) a.append_model(mdl, atom_files='test', align_codes='test') m.add_alignment(a) m = m.reshape(features, [0] * len(features), [-1] * len(features)) return m
def calculate_model_for_graph(calc_params, dla, dmu): la = 1 # dla = 0.05 mu = 10 # dmu = 1 loads1 = np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]) loads2 = np.arange(0.9, 1, 0.01) loads2 = np.concatenate((loads2, [0.999])) times1 = [] times2 = [] tmax = 100 for p in loads1: la = p * mu m1, d1, m2, d2 = calc_params(la, dla, mu, dmu) model = modeller.Model(m1, d1, m2, d2, 1, 1, 0) _, t = model.time_based_modelling(tmax, 0.01) # print(t) times1.append(t) for p in loads2: la = p * mu m1, d1, m2, d2 = calc_params(la, dla, mu, dmu) model = modeller.Model(m1, d1, m2, d2, 1, 1, 0) _, t = model.time_based_modelling(tmax, 0.001) # print(t) times2.append(t) return np.concatenate(([0], loads1, loads2)), np.concatenate( ([times1[0]], times1, times2))
def get_pdb_seq(pdb, chain): ''' Read a PDB[pdb] input and outputs a sequence of a desired chain[chain]. ''' import modeller e = modeller.Environ() m = modeller.Model(e, file=pdb, model_segment=('FIRST:' + chain, 'LAST:' + chain)) # BLAST will get confused if the PDB file contains non-standard ATOM # records (e.g. HIE rather than HIS) _detect_invalid_residue_types(m) return "".join(r.code for r in m.residues)
def test_detect_invalid_residue_types_bad(self): """Test _detect_invalid_residue_types() with bad sequence""" with utils.temporary_directory() as tmpdir: fname = os.path.join(tmpdir, 'test.pdb') with open(fname, 'w') as fh: fh.write(""" ATOM 1 N CYS A 1 18.511 -1.416 15.632 1.00 6.84 C ATOM 2 C CYS A 1 18.511 -1.416 15.632 1.00 6.84 C ATOM 3 N HIE A 2 18.511 -1.416 15.632 1.00 6.84 C ATOM 4 C HIE A 2 18.511 -1.416 15.632 1.00 6.84 C ATOM 5 N HSD B 3 18.511 -1.416 15.632 1.00 6.84 C ATOM 6 C HSD B 3 18.511 -1.416 15.632 1.00 6.84 C """) e = modeller.Environ() m = modeller.Model(e, file=fname) self.assertRaises(cleaning.InvalidResiduesError, cleaning._detect_invalid_residue_types, m)
def test_get_coordinates_sc(self): """Test get_coordinates_sc() function""" e = modeller.Environ() m = modeller.Model(e) coord = cryptosite.analysis.get_coordinates_sc( m, os.path.join(TOPDIR, 'test', 'input', 'test_coord.pdb')) self.assertEqual(len(coord), 4) # First residue is a GLY with no CA -> no coordinates self.assertEqual(coord[0], None) # Second residue is a GLY with CA -> coordinates are those of # the GLY (0,0,0) self.assertAlmostEqual(coord[1].x, 0., places=1) self.assertAlmostEqual(coord[1].y, 0., places=1) self.assertAlmostEqual(coord[1].z, 0., places=1) # Third residue is a MET with no sidechain -> no coordinates self.assertEqual(coord[2], None) # Fourth residue is a MET with a sidechain -> mean coordinates returned self.assertAlmostEqual(coord[3].x, 5., places=1) self.assertAlmostEqual(coord[3].y, 10., places=1) self.assertAlmostEqual(coord[3].z, 15., places=1)
def on_process(self): print('process') layout = self.ui.externalLayout.itemAt(0) print(layout) self.read_params() la1 = self.la1 dla1 = self.dla1 la2 = self.la2 dla2 = self.dla2 mu1 = self.mu1 dmu1 = self.dmu1 mu2 = self.mu2 dmu2 = self.dmu2 tmax = self.tmax mT11, dT11, mT12, dT12, mT21, dT21, mT22, dT22 = calculate_params( la1, dla1, la2, dla2, mu1, dmu1, mu2, dmu2) model = modeller.Model([mT11, mT12], [dT11, dT12], [mT21, mT22], [dT21, dT22], 2, 1, 0) print('start') ro = (la1 + la2) / ((mu1 + mu2) / 2) avg_queue_size, avg_queue_time, processed_requests = model.time_based_modellingg( tmax, 0.001) result = f'Расчетная загрузка системы: {ro}\n' \ f'Среднее количество заявок в системе: {avg_queue_size}\n' \ f'Среднее время ожидания: {avg_queue_time}\n' \ f'Обработано заявок: {processed_requests}' QMessageBox.information(self, 'Result', result) self.set_free_point()
def get_qioft(landscape, rcut=11.): """Calculate Qi for all models in a landscape.""" import modeller modeller.log.none() e = modeller.Environ() e.io.hetatm = False m = modeller.Model(e) for dirname in _get_subdirectories(landscape): with open(os.path.join(dirname, 'list')) as fh: temp1 = 'pm_' + fh.readline().strip() pm = os.path.join(dirname, temp1) models = sorted(glob.glob(os.path.join(dirname, 'pm.pdb.B[1-8]*.pdb'))) coord = get_coordinates_sc(m, pm) dist = get_distances(coord, rcut) with open( os.path.join(dirname, 'qioft_%s_%dsc.dat' % (temp1, int(rcut))), 'w') as fh: for model in models: get_qi(m, len(coord), dist, model, fh) fh.write('\n')
def build_model(pdb, chains): ''' Build model using Modeller, treating residues in the structure as rigid, and loop modeling for the rest. ''' import modeller from modeller.automodel import LoopModel, AutoModel, assess # --- get gaps gaps = get_gaps('alignment.pir') with open('gaps_%s.txt' % pdb, 'w') as out: out.write(pdb + '_mdl\t' + str(gaps)) # --- set up modeling env = modeller.Environ() env.io.atom_files_directory = ['.', '../atom_files'] class MyLoop(LoopModel): def select_loop_atoms(self): gaps = get_gaps('alignment.pir') return modeller.Selection( self.residue_range(i.split(',')[0], i.split(',')[1]) for i in gaps) def special_restraints(self, aln): rsr = self.restraints wholeSel = modeller.Selection(self) - self.select_loop_atoms() r = modeller.RigidBody(wholeSel) rsr.rigid_bodies.append(r) if len(gaps) > 0: a = MyLoop( env, alnfile='alignment.pir', # alignment filename knowns=pdb, # codes of the templates sequence=pdb.lower() + '_' + 'X', # code of the target loop_assess_methods=assess.normalized_dope) a.starting_model = 1 # index of the first model a.ending_model = 1 # index of the last model a.loop.starting_model = 1 # First loop model a.loop.ending_model = 10 # Last loop model a.make() # do modeling and loop refinement ok_models = [i for i in a.loop.outputs if i['failure'] is None] # -- select best model zscores = sorted([(i['name'], i['Normalized DOPE score']) for i in ok_models], key=itemgetter(1)) bestModel = zscores[0][0] os.system('mv %s %s_mdl.pdb' % (bestModel, pdb)) os.system('rm %s_X.*' % (pdb.lower(), )) else: a = AutoModel(env, alnfile='alignment.pir', knowns=pdb, sequence=pdb.lower() + '_X', assess_methods=(assess.DOPE, )) a.very_fast() a.starting_model = 1 a.ending_model = 1 a.make(exit_stage=2) os.system('mv %s_X.ini %s_mdl.pdb' % (pdb.lower(), pdb)) os.system('rm %s_X.*' % (pdb.lower(), )) if len(chains) == 1: mdl = modeller.Model(env, file='XXX_mdl') mdl.rename_segments(segment_ids='A') mdl.write(file='%s_mdl.pdb' % (pdb))
def graphic(table_clicks, add_clicks, clients_number, rel_min1, rel_max1, rel_min2, rel_max2, norm_min1, norm_max1, norm_d_min1, norm_d_max1, norm_min2, norm_max2, norm_d_min2, norm_d_max2, x1_new, x2_new, x3_new, x4_new, x5_new, x6_new): global df, n_add, experim for i in range(experim): array_x[i] = array_x[i][1:] if (add_clicks > n_add): n_add = add_clicks x1_new = float(x1_new) x2_new = float(x2_new) x3_new = float(x3_new) x4_new = float(x4_new) x5_new = float(x4_new) x6_new = float(x4_new) experim += 1 array_x.append(get_row([x1_new, x2_new, x3_new, x4_new, x5_new, x6_new], 6)) f1_b = float(rel_min1) f1_e = float(rel_max1) f2_b = float(rel_min2) f2_e = float(rel_max2) f3_b = float(norm_min1) f3_e = float(norm_max1) f4_b = float(norm_d_min1) f4_e = float(norm_d_max1) f5_b = float(norm_min2) f5_e = float(norm_max2) f6_b = float(norm_d_min2) f6_e = float(norm_d_max2) r = True if 2 * (f1_b + f1_e + f2_b + f2_e) / (f3_b + f3_e + f5_b + f5_e) > 0.8 else False i = 0 for row in array_x: rel1 = convert_factor_to_value(float(rel_min1), float(rel_max1), row[1]) rel2 = convert_factor_to_value(float(rel_min2), float(rel_max2), row[2]) norm1 = convert_factor_to_value(float(norm_min1), float(norm_max1), row[3]) norm_d1 = convert_factor_to_value(float(norm_d_min1), float(norm_d_max1), row[4]) norm2 = convert_factor_to_value(float(norm_min2), float(norm_max2), row[5]) norm_d2 = convert_factor_to_value(float(norm_d_min2), float(norm_d_max2), row[6]) c_rel1 = calculate_reley_param(rel1) c_rel2 = calculate_reley_param(rel2) c_norm1, c_norm_d1 = calculate_gauss_params(norm1, norm_d1) c_norm2, c_norm_d2 = calculate_gauss_params(norm2, norm_d2) model = modeller.Model([c_rel1, c_rel2], [c_norm1, c_norm2], [c_norm_d1, c_norm_d2], 2, 1, 0) avg_queue_size, avg_queue_time, processed_requests = model.time_based_modellingg(tmax, 0.001) print(i) array_x[i][70] = round(avg_queue_time, 5) i += 1 b0 = calculate_b_ockp(0, 1, [array_x[i][0] for i in range(count)], [array_x[i][70] for i in range(count)], count) b1 = calculate_b_ockp(f1_b, f1_e, [array_x[i][1] for i in range(count)], [array_x[i][70] for i in range(count)], count) b2 = calculate_b_ockp(f2_b, f2_e, [array_x[i][2] for i in range(count)], [array_x[i][70] for i in range(count)], count) b3 = calculate_b_ockp(f3_b, f3_e, [array_x[i][3] for i in range(count)], [array_x[i][70] for i in range(count)], count) b4 = calculate_b_ockp(f4_b, f4_e, [array_x[i][4] for i in range(count)], [array_x[i][70] for i in range(count)], count) b5 = calculate_b_ockp(f5_b, f5_e, [array_x[i][5] for i in range(count)], [array_x[i][70] for i in range(count)], count) b6 = calculate_b_ockp(f6_b, f6_e, [array_x[i][6] for i in range(count)], [array_x[i][70] for i in range(count)], count) b12 = calculate_b_ockp(f1_b * f2_b, f1_e * f2_e, [array_x[i][7] for i in range(count)], [array_x[i][70] for i in range(count)], count) b13 = calculate_b_ockp(f1_b * f3_b, f1_e * f3_e, [array_x[i][8] for i in range(count)], [array_x[i][70] for i in range(count)], count) b14 = calculate_b_ockp(f1_b * f4_b, f1_e * f4_e, [array_x[i][9] for i in range(count)], [array_x[i][70] for i in range(count)], count) b15 = calculate_b_ockp(f1_b * f5_b, f1_e * f5_e, [array_x[i][10] for i in range(count)], [array_x[i][70] for i in range(count)], count) b16 = calculate_b_ockp(f1_b * f6_b, f1_e * f6_e, [array_x[i][11] for i in range(count)], [array_x[i][70] for i in range(count)], count) b23 = calculate_b(f2_b * f3_b, f2_e * f3_e, [array_x[i][12] for i in range(count)], [array_x[i][70] for i in range(count)], count) b24 = calculate_b_ockp(f2_b * f4_b, f2_e * f4_e, [array_x[i][13] for i in range(count)], [array_x[i][70] for i in range(count)], count) b25 = calculate_b_ockp(f2_b * f5_b, f2_e * f5_e, [array_x[i][14] for i in range(count)], [array_x[i][70] for i in range(count)], count) b26 = calculate_b_ockp(f2_b * f6_b, f2_e * f6_e, [array_x[i][15] for i in range(count)], [array_x[i][70] for i in range(count)], count) b34 = calculate_b_ockp(f3_b * f4_b, f3_e * f4_e, [array_x[i][16] for i in range(count)], [array_x[i][70] for i in range(count)], count) b35 = calculate_b_ockp(f3_b * f5_b, f3_e * f5_e, [array_x[i][17] for i in range(count)], [array_x[i][70] for i in range(count)], count) b36 = calculate_b_ockp(f3_b * f6_b, f3_e * f6_e, [array_x[i][18] for i in range(count)], [array_x[i][70] for i in range(count)], count) b45 = calculate_b_ockp(f4_b * f5_b, f4_e * f5_e, [array_x[i][19] for i in range(count)], [array_x[i][70] for i in range(count)], count) b46 = calculate_b_ockp(f4_b * f6_b, f4_e * f6_e, [array_x[i][20] for i in range(count)], [array_x[i][70] for i in range(count)], count) b56 = calculate_b_ockp(f5_b * f6_b, f5_e * f6_e, [array_x[i][21] for i in range(count)], [array_x[i][70] for i in range(count)], count) b123 = calculate_b_ockp(f1_b * f2_b * f3_b, f1_e * f2_e * f3_e, [array_x[i][22] for i in range(count)], [array_x[i][70] for i in range(count)], count) b124 = calculate_b_ockp(f1_b * f2_b * f4_b, f1_e * f2_e * f4_e, [array_x[i][23] for i in range(count)], [array_x[i][70] for i in range(count)], count) b125 = calculate_b_ockp(f1_b * f2_b * f5_b, f1_e * f2_e * f5_e, [array_x[i][24] for i in range(count)], [array_x[i][70] for i in range(count)], count) b126 = calculate_b_ockp(f1_b * f2_b * f6_b, f1_e * f2_e * f6_e, [array_x[i][25] for i in range(count)], [array_x[i][70] for i in range(count)], count) b134 = calculate_b_ockp(f1_b * f3_b * f4_b, f1_e * f3_e * f4_e, [array_x[i][26] for i in range(count)], [array_x[i][70] for i in range(count)], count) b135 = calculate_b_ockp(f1_b * f3_b * f5_b, f1_e * f3_e * f5_e, [array_x[i][27] for i in range(count)], [array_x[i][70] for i in range(count)], count) b136 = calculate_b_ockp(f1_b * f3_b * f6_b, f1_e * f3_e * f6_e, [array_x[i][28] for i in range(count)], [array_x[i][70] for i in range(count)], count) b145 = calculate_b_ockp(f1_b * f4_b * f5_b, f1_e * f4_e * f5_e, [array_x[i][29] for i in range(count)], [array_x[i][70] for i in range(count)], count) b146 = calculate_b_ockp(f1_b * f4_b * f6_b, f1_e * f4_e * f6_e, [array_x[i][30] for i in range(count)], [array_x[i][70] for i in range(count)], count) b156 = calculate_b_ockp(f1_b * f5_b * f6_b, f1_e * f5_e * f6_e, [array_x[i][31] for i in range(count)], [array_x[i][70] for i in range(count)], count) b234 = calculate_b_ockp(f2_b * f3_b * f4_b, f2_e * f3_e * f4_e, [array_x[i][32] for i in range(count)], [array_x[i][70] for i in range(count)], count) b235 = calculate_b_ockp(f2_b * f3_b * f5_b, f2_e * f3_e * f5_e, [array_x[i][33] for i in range(count)], [array_x[i][70] for i in range(count)], count) b236 = calculate_b_ockp(f2_b * f3_b * f6_b, f2_e * f3_e * f6_e, [array_x[i][34] for i in range(count)], [array_x[i][70] for i in range(count)], count) b245 = calculate_b_ockp(f2_b * f4_b * f5_b, f2_e * f4_e * f5_e, [array_x[i][35] for i in range(count)], [array_x[i][70] for i in range(count)], count) b246 = calculate_b_ockp(f2_b * f4_b * f6_b, f2_e * f4_e * f6_e, [array_x[i][36] for i in range(count)], [array_x[i][70] for i in range(count)], count) b256 = calculate_b_ockp(f2_b * f5_b * f6_b, f2_e * f5_e * f6_e, [array_x[i][37] for i in range(count)], [array_x[i][70] for i in range(count)], count) b345 = calculate_b_ockp(f3_b * f4_b * f5_b, f3_e * f4_e * f5_e, [array_x[i][38] for i in range(count)], [array_x[i][70] for i in range(count)], count) b346 = calculate_b_ockp(f3_b * f4_b * f6_b, f3_e * f4_e * f6_e, [array_x[i][39] for i in range(count)], [array_x[i][70] for i in range(count)], count) b356 = calculate_b_ockp(f3_b * f5_b * f6_b, f3_e * f5_e * f6_e, [array_x[i][40] for i in range(count)], [array_x[i][70] for i in range(count)], count) b456 = calculate_b_ockp(f4_b * f5_b * f6_b, f4_e * f5_e * f6_e, [array_x[i][41] for i in range(count)], [array_x[i][70] for i in range(count)], count) b1234 = calculate_b_ockp(f1_b * f2_b * f3_b * f4_b, f1_e * f2_e * f3_e * f4_e, [array_x[i][42] for i in range(count)], [array_x[i][70] for i in range(count)], count) b1235 = calculate_b_ockp(f1_b * f2_b * f3_b * f5_b, f1_e * f2_e * f3_e * f5_e, [array_x[i][43] for i in range(count)], [array_x[i][70] for i in range(count)], count) b1236 = calculate_b_ockp(f1_b * f2_b * f3_b * f6_b, f1_e * f2_e * f3_e * f6_e, [array_x[i][44] for i in range(count)], [array_x[i][70] for i in range(count)], count) b1245 = calculate_b_ockp(f1_b * f2_b * f4_b * f5_b, f1_e * f2_e * f4_e * f5_e, [array_x[i][45] for i in range(count)], [array_x[i][70] for i in range(count)], count) b1246 = calculate_b_ockp(f1_b * f2_b * f4_b * f6_b, f1_e * f2_e * f4_e * f6_e, [array_x[i][46] for i in range(count)], [array_x[i][70] for i in range(count)], count) b1256 = calculate_b_ockp(f1_b * f2_b * f5_b * f6_b, f1_e * f2_e * f5_e * f6_e, [array_x[i][47] for i in range(count)], [array_x[i][70] for i in range(count)], count) b1345 = calculate_b_ockp(f1_b * f3_b * f4_b * f5_b, f1_e * f3_e * f4_e * f5_e, [array_x[i][48] for i in range(count)], [array_x[i][70] for i in range(count)], count) b1346 = calculate_b_ockp(f1_b * f3_b * f4_b * f6_b, f1_e * f3_e * f4_e * f6_e, [array_x[i][49] for i in range(count)], [array_x[i][70] for i in range(count)], count) b1356 = calculate_b_ockp(f1_b * f3_b * f5_b * f6_b, f1_e * f3_e * f5_e * f6_e, [array_x[i][50] for i in range(count)], [array_x[i][70] for i in range(count)], count) b1456 = calculate_b_ockp(f1_b * f4_b * f5_b * f6_b, f1_e * f4_e * f5_e * f6_e, [array_x[i][51] for i in range(count)], [array_x[i][70] for i in range(count)], count) b2345 = calculate_b_ockp(f2_b * f3_b * f4_b * f5_b, f2_e * f3_e * f4_e * f5_e, [array_x[i][52] for i in range(count)], [array_x[i][70] for i in range(count)], count) b2346 = calculate_b_ockp(f2_b * f3_b * f4_b * f6_b, f2_e * f3_e * f4_e * f6_e, [array_x[i][53] for i in range(count)], [array_x[i][70] for i in range(count)], count) b2356 = calculate_b_ockp(f2_b * f3_b * f5_b * f6_b, f2_e * f3_e * f5_e * f6_e, [array_x[i][54] for i in range(count)], [array_x[i][70] for i in range(count)], count) b2456 = calculate_b_ockp(f2_b * f4_b * f5_b * f6_b, f2_e * f4_e * f5_e * f6_e, [array_x[i][55] for i in range(count)], [array_x[i][70] for i in range(count)], count) b3456 = calculate_b_ockp(f3_b * f4_b * f5_b * f6_b, f3_e * f4_e * f5_e * f6_e, [array_x[i][56] for i in range(count)], [array_x[i][70] for i in range(count)], count) b12345 = calculate_b_ockp(f1_b * f2_b * f3_b * f4_b * f5_b, f1_e * f2_e * f3_e * f4_e * f5_e, [array_x[i][57] for i in range(count)], [array_x[i][70] for i in range(count)], count) b12346 = calculate_b_ockp(f1_b * f2_b * f3_b * f4_b * f6_b, f1_e * f2_e * f3_e * f4_e * f6_e, [array_x[i][58] for i in range(count)], [array_x[i][70] for i in range(count)], count) b12356 = calculate_b_ockp(f1_b * f2_b * f3_b * f5_b * f6_b, f1_e * f2_e * f3_e * f5_e * f6_e, [array_x[i][59] for i in range(count)], [array_x[i][70] for i in range(count)], count) b12456 = calculate_b_ockp(f1_b * f2_b * f4_b * f5_b * f6_b, f1_e * f2_e * f4_e * f5_e * f6_e, [array_x[i][60] for i in range(count)], [array_x[i][70] for i in range(count)], count) b13456 = calculate_b_ockp(f1_b * f3_b * f4_b * f5_b * f6_b, f1_e * f3_e * f4_e * f5_e * f6_e, [array_x[i][61] for i in range(count)], [array_x[i][70] for i in range(count)], count) b23456 = calculate_b_ockp(f2_b * f3_b * f4_b * f5_b * f6_b, f2_e * f3_e * f4_e * f5_e * f6_e, [array_x[i][62] for i in range(count)], [array_x[i][70] for i in range(count)], count) b123456 = calculate_b_ockp(f1_b * f2_b * f3_b * f4_b * f5_b * f6_b, f1_e * f2_e * f3_e * f4_e * f5_e * f6_e, [array_x[i][63] for i in range(count)], [array_x[i][70] for i in range(count)], count) b11 = calculate_b_ockp(0, 1, [array_x[i][64] for i in range(count)], [array_x[i][70] for i in range(count)], count) b22 = calculate_b_ockp(0, 1, [array_x[i][65] for i in range(count)], [array_x[i][70] for i in range(count)], count) b33 = calculate_b_ockp(0, 1, [array_x[i][66] for i in range(count)], [array_x[i][70] for i in range(count)], count) b44 = calculate_b_ockp(0, 1, [array_x[i][67] for i in range(count)], [array_x[i][70] for i in range(count)], count) b55 = calculate_b_ockp(0, 1, [array_x[i][68] for i in range(count)], [array_x[i][70] for i in range(count)], count) b66 = calculate_b_ockp(0, 1, [array_x[i][69] for i in range(count)], [array_x[i][70] for i in range(count)], count) b0 = b0 - (b11+b22+b33+b44+b55+b66) * s no_line = f"y={round(b0, 5)}+({round(b1, 5)})*x1+({round(b2, 5)})*x2+({round(b3, 5)})*x3+({round(b4, 5)})*x4+({round(b5, 5)})*x5+({round(b6, 5)})*x6+\ ({round(b12, 5)})*x1*x2+({round(b13, 5)})*x1*x3+({round(b14, 5)})*x1*x4+({round(b15, 5)})*x1*x5+({round(b16, 5)})*x1*x6+\ ({round(b23, 5)})*x2*x3+({round(b24, 5)})*x2*x4+({round(b25, 5)})*x2*x5+({round(b26, 5)})*x2*x6+\ ({round(b34, 5)})*x3*x4+({round(b35, 5)})*x3*x5+({round(b36, 5)})*x3*x6+\ ({round(b45, 5)})*x4*x5+({round(b46, 5)})*x4*x6+\ ({round(b56, 5)})*x5*x6+\ ({round(b123, 5)})*x1*x2*x3+({round(b124, 5)})*x1*x2*x4+({round(b125, 5)})*x1*x2*x5+({round(b126, 5)})*x1*x2*x6+\ ({round(b134, 5)})*x1*x3*x4+({round(b135, 5)})*x1*x3*x5+({round(b136, 5)})*x1*x3*x6+\ ({round(b145, 5)})*x1*x4*x5+({round(b146, 5)})*x1*x4*x6+\ ({round(b156, 5)})*x1*x5*x6+\ ({round(b234, 5)})*x2*x3*x4+({round(b235, 5)})*x2*x3*x5+({round(b236, 5)})*x2*x3*x6+\ ({round(b245, 5)})*x2*x4*x5+({round(b246, 5)})*x2*x4*x6+\ ({round(b256, 5)})*x2*x5*x6+\ ({round(b345, 5)})*x3*x4*x5+({round(b346, 5)})*x3*x4*x6+\ ({round(b356, 5)})*x3*x5*x6+\ ({round(b456, 5)})*x4*x5*x6+\ ({round(b1234, 5)})*x1*x2*x3*x4+({round(b1235, 5)})*x1*x2*x3*x5+({round(b1236, 5)})*x1*x2*x3*x6+\ ({round(b1245, 5)})*x1*x2*x4*x5+({round(b1246, 5)})*x1*x2*x4*x6+\ ({round(b1256, 5)})*x1*x2*x5*x6+\ ({round(b1345, 5)})*x1*x3*x4*x5+({round(b1346, 5)})*x1*x3*x4*x6+\ ({round(b1356, 5)})*x1*x3*x5*x6+\ ({round(b1456, 5)})*x1*x4*x5*x6+\ ({round(b2345, 5)})*x2*x3*x4*x5+({round(b2346, 5)})*x2*x3*x4*x6+\ ({round(b2356, 5)})*x2*x3*x5*x6+\ ({round(b2456, 5)})*x2*x4*x5*x6+\ ({round(b3456, 5)})*x3*x4*x5*x6+\ ({round(b12345, 5)})*x1*x2*x3*x4*x5+({round(b12346, 5)})*x1*x2*x3*x4*x6+\ ({round(b12356, 5)})*x1*x2*x3*x5*x6+\ ({round(b12456, 5)})*x1*x2*x4*x5*x6+\ ({round(b13456, 5)})*x1*x3*x4*x5*x6+\ ({round(b23456, 5)})*x2*x3*x4*x5*x6+\ ({round(b123456, 5)})*x1*x2*x3*x4*x5*x6+\ ({round(b11 if b11 > 0 else -b11, 5)})*(x1^2-s)+\ ({round(b22 if b22 > 0 else -b22, 5)})*(x2^2-s)+\ ({round(b33 if not r else (-b33 if b33 > 0 else b33), 5)})*(x3^2-s)+\ ({round(b44, 5)})*(x4^2-s)+\ ({round(b55 if not r else (-b55 if b55 > 0 else b55), 5)})*(x5^2-s)+\ ({round(b66, 5)})*(x6^2-s)" i = 0 for row in array_x: x1 = array_x[i][1] x2 = array_x[i][2] x3 = array_x[i][3] x4 = array_x[i][4] x5 = array_x[i][5] x6 = array_x[i][6] array_x[i][71] = round(fabs(b0 + b1 * x1 + b2 * x2 + b3 * x3 + b4 * x4 + b5 * x5 + b6 * x6 + \ b12 * x1 * x2 + b13 * x1 * x3 + b14 * x1 * x4 + b15 * x1 * x5 + b16 * x1 * x6 + \ b23 * x2 * x3 + b24 * x2 * x4 + b25 * x2 * x5 + b26 * x2 * x6+\ b34 * x3 * x4 + b35 * x3 * x5 + b36 * x3 * x6 + \ b45 * x4 * x5 + b46 * x4 * x6 + \ b56 * x5 * x6 + \ b123 * x1 * x2 * x3 + b124 * x1 * x2 * x4 + b125 * x1 * x2 * x5+ b126 * x1 * x2 * x6 + \ b134 * x1 * x3 * x4 + b135 * x1 * x3 * x5 + b136 * x1 * x3 * x6 + \ b145 * x1 * x4 * x5 + b146 * x1 * x4 * x6 + \ b156 * x1 * x5 * x6 + \ b234 * x2 * x3 * x4 + b235 * x2 * x3 * x5 + b236 * x2 * x3 * x6 + \ b245 * x2 * x4 * x5 + b246 * x2 * x4 * x6 + \ b256 * x2 * x5 * x6 + \ b345 * x3 * x4 * x5 + b346 * x3 * x4 * x6 + \ b356 * x3 * x5 * x6 + \ b456 * x4 * x5 * x6 + \ b1234 * x1 * x2 * x3 * x4 + b1235 * x1 * x2 * x3 * x5 + b1236 * x1 * x2 * x3 * x6+\ b1245 * x1 * x2 * x4 * x5 + b1246 * x1 * x2 * x4 * x6 + \ b1256 * x1 * x2 * x5 * x6 + \ b1345 * x1 * x3 * x4 * x5 + b1346 * x1 * x3 * x4 * x6 + \ b1356 * x1 * x3 * x5 * x6 + \ b1456 * x1 * x4 * x5 * x6 + \ b2345 * x2 * x3 * x4 * x5 + b2346 * x2 * x3 * x4 * x6 + \ b2356 * x2 * x3 * x5 * x6 + \ b2456 * x2 * x4 * x5 * x6 + \ b3456 * x3 * x4 * x5 * x6 + \ b12345 * x1 * x2 * x3 * x4 * x5 + b12346 * x1 * x2 * x3 * x4 * x6 + \ b12356 * x1 * x2 * x3 * x5 * x6 + \ b12456 * x1 * x2 * x4 * x5 * x6 + \ b13456 * x1 * x3 * x4 * x5 * x6 + \ b23456 * x2 * x3 * x4 * x5 * x6 + \ b123456 * x1 * x2 * x3 * x4 * x5 * x6 + \ b11 * (x1*x1 - s) + \ b22 * (x2*x2 - s) + \ b33 * (x3*x3 - s) + \ b44 * (x4*x4 - s) + \ b55 * (x5*x5 - s) + \ b66 * (x6*x6 - s)), 5) array_x[i][72] = round(fabs(array_x[i][70] - array_x[i][71]), 5) i += 1 for i in range(experim): array_x[i] = [i+1] + array_x[i] df = pd.DataFrame(array_x, columns=columns_table) return [[{"name": i, "id": i} for i in df.columns], df.to_dict('records'), no_line]
def calculate_ffe(self): layout = self.ui.externalLayout.itemAt(1) tableWidget = self.ui.tableWidget rows = tableWidget.rowCount() cols = tableWidget.columnCount() Xmin, Xmax = self.read_model_params() print(Xmin, Xmax) planningTable = [[tableWidget.item(i, j).text() for j in range(cols)] for i in range(rows)] coefMatrix, planningMatrix, checkVector = process_matrixes( planningTable) factorMatrix = np.matrix( list(map(lambda row: row[1:7], planningTable.copy()))) Y = [0 for i in range(65)] for i in range(len(factorMatrix.tolist())): la1 = convert_factor_to_value(Xmin[0], Xmax[0], float(factorMatrix.item((i, 0)))) dla1 = convert_factor_to_value(Xmin[1], Xmax[1], float(factorMatrix.item((i, 1)))) la2 = convert_factor_to_value(Xmin[2], Xmax[2], float(factorMatrix.item((i, 2)))) dla2 = convert_factor_to_value(Xmin[3], Xmax[3], float(factorMatrix.item((i, 3)))) mu = convert_factor_to_value(Xmin[4], Xmax[4], float(factorMatrix.item((i, 4)))) dmu = convert_factor_to_value(Xmin[5], Xmax[5], float(factorMatrix.item((i, 5)))) # print(la, dla, mu, dmu) mT11, dT11, mT12, dT12, mT2, dT2 = calculate_params( la1, dla1, la2, dla2, mu, dmu) model = modeller.Model([mT11, mT12], [dT11, dT12], mT2, dT2, 2, 1, 0) avg_queue_size, avg_queue_time, processed_requests = model.time_based_modellingg( 100, 0.001) # print(avg_queue_time) Y[i] = avg_queue_time tableWidget.setItem( i, 64, QTableWidgetItem(str(round(avg_queue_time, 4)))) Yt = [Y[-1]] Y = np.array(Y[:-1]) print("calculated ffe") B = (coefMatrix @ Y).tolist()[0] self.set_b_table(B, self.ui.bTableWidget, 0) # print(B[:5]) Yl = np.array( list( map(lambda row: row[:7], planningMatrix.tolist() + [checkVector.tolist()]))) @ np.array(B[:7]) Ypn = np.array(planningMatrix.tolist() + [checkVector.tolist()]) @ np.array(B) resYList = Y.tolist() + Yt for i in range(len(resYList)): tableWidget.setItem( i, 65, QTableWidgetItem(str(round(Yl.tolist()[i], 4)))) tableWidget.setItem( i, 66, QTableWidgetItem(str(round(Ypn.tolist()[i], 4)))) tableWidget.setItem( i, 67, QTableWidgetItem( str( abs( round( round(resYList[i], 6) - round(Yl.tolist()[i], 6), 6))))) tableWidget.setItem( i, 68, QTableWidgetItem( str( abs( round( round(resYList[i], 6) - round(Ypn.tolist()[i], 6), 6)))))
def calculate_pfe(self): tableWidget = self.ui.tableWidget2 rows = tableWidget.rowCount() cols = tableWidget.columnCount() Xmin, Xmax = self.read_model_params() planningTable = [[ float(tableWidget.item(i, j).text()) for j in range(64) ] for i in range(rows)] factorMatrix = np.matrix( list(map(lambda row: row[1:7], planningTable.copy()))) checkVector = np.array(planningTable.copy()[-1][:64]) Y = [0 for i in range(9)] for i in range(len(factorMatrix.tolist())): la1 = convert_factor_to_value(Xmin[0], Xmax[0], float(factorMatrix.item((i, 0)))) dla1 = convert_factor_to_value(Xmin[1], Xmax[1], float(factorMatrix.item((i, 1)))) la2 = convert_factor_to_value(Xmin[2], Xmax[2], float(factorMatrix.item((i, 2)))) dla2 = convert_factor_to_value(Xmin[3], Xmax[3], float(factorMatrix.item((i, 3)))) mu = convert_factor_to_value(Xmin[4], Xmax[4], float(factorMatrix.item((i, 4)))) dmu = convert_factor_to_value(Xmin[5], Xmax[5], float(factorMatrix.item((i, 5)))) # print(la, dla, mu, dmu) mT11, dT11, mT12, dT12, mT2, dT2 = calculate_params( la1, dla1, la2, dla2, mu, dmu) model = modeller.Model([mT11, mT12], [dT11, dT12], mT2, dT2, 2, 1, 0) avg_queue_size, avg_queue_time, processed_requests = model.time_based_modellingg( 100, 0.001) # print(avg_queue_time) Y[i] = avg_queue_time tableWidget.setItem( i, 64, QTableWidgetItem(str(round(avg_queue_time, 4)))) Yt = [Y[-1]] Y = np.array(Y[:-1]) print("calculated pfe") B = [ np.array( [float(planningTable[i][k]) / len(Y) for i in range(len(Y))]) @ Y for k in range(64) ] Yl = np.array( list( map(lambda row: row[:7], planningTable + [checkVector.tolist()]))) @ np.array(B[:7]) Bl = B[:7] + [0 for i in range(7, len(B))] self.set_b_table(Bl, self.ui.bTableWidget2, 1) Bpn = B.copy() for i in range(0, 64): B[i] = B[i] / self.count_eq_rows(planningTable, i, len(planningTable[0])) self.set_b_table(B, self.ui.bTableWidget2, 0) for i in range(0, 22): Bpn[i] = Bpn[i] / self.count_eq_rows(planningTable, i, 22) for i in range(22, 64): Bpn[i] = 0 self.set_b_table(Bpn, self.ui.bTableWidget2, 2) # B for fully non-linear, Bpn for quadratic only Ypn = np.array(planningTable + [checkVector.tolist()]) @ np.array(Bpn) resYList = Y.tolist() + Yt for i in range(len(resYList)): tableWidget.setItem( i, 65, QTableWidgetItem(str(round(Yl.tolist()[i], 4)))) tableWidget.setItem( i, 66, QTableWidgetItem(str(round(Ypn.tolist()[i], 4)))) tableWidget.setItem( i, 67, QTableWidgetItem( str( abs( round( round(resYList[i], 6) - round(Yl.tolist()[i], 6), 6))))) tableWidget.setItem( i, 68, QTableWidgetItem( str( abs( round( round(resYList[i], 6) - round(Ypn.tolist()[i], 6), 6)))))
def calculate_occe(self): tableWidget = self.ui.tableWidget rows = tableWidget.rowCount() cols = tableWidget.columnCount() Xmin, Xmax = self.read_model_params() self.init_table() self.set_free_point() planningTable = [[tableWidget.item(i, j).text() for j in range(cols)] for i in range(rows)] planningMatrix, checkVector = process_matrixes(planningTable) factorMatrix = np.matrix( list(map(lambda row: row[1:9], planningTable.copy()))) Y = [0 for i in range(257 + 16 + 1)] for i in range(len(factorMatrix.tolist())): la1 = convert_factor_to_value(Xmin[0], Xmax[0], float(factorMatrix.item((i, 0)))) dla1 = convert_factor_to_value(Xmin[1], Xmax[1], float(factorMatrix.item((i, 1)))) la2 = convert_factor_to_value(Xmin[2], Xmax[2], float(factorMatrix.item((i, 2)))) dla2 = convert_factor_to_value(Xmin[3], Xmax[3], float(factorMatrix.item((i, 3)))) mu1 = convert_factor_to_value(Xmin[4], Xmax[4], float(factorMatrix.item((i, 4)))) dmu1 = convert_factor_to_value(Xmin[5], Xmax[5], float(factorMatrix.item((i, 5)))) mu2 = convert_factor_to_value(Xmin[6], Xmax[6], float(factorMatrix.item((i, 6)))) dmu2 = convert_factor_to_value(Xmin[7], Xmax[7], float(factorMatrix.item((i, 7)))) mT11, dT11, mT12, dT12, mT21, dT21, mT22, dT22 = calculate_params( la1, dla1, la2, dla2, mu1, dmu1, mu2, dmu2) model = modeller.Model([mT11, mT12], [dT11, dT12], [mT21, mT22], [dT21, dT22], 2, 1, 0) avg_queue_size, avg_queue_time, processed_requests = model.time_based_modellingg( 100, 0.001) Y[i] = avg_queue_time tableWidget.setItem( i, 256 + 8, QTableWidgetItem(str(round(avg_queue_time, 4)))) Yt = [Y[-1]] Y = np.array(Y[:-1]) transPlanningMatrix = np.transpose(planningMatrix.copy()) B = [(transPlanningMatrix[i] @ Y) / self.calc_b_divider(planningMatrix, i) for i in range(256 + 8)] self.set_b_table(B, self.ui.bTableWidget, 0) B[0] = B[0] + (B[-8] * self.S + B[-7] * self.S + B[-6] * self.S + B[-5] * self.S \ + B[-4] * self.S + B[-3] * self.S + B[-2] * self.S + B[-1] * self.S) Yn = np.array(planningMatrix + [checkVector.tolist()]) @ np.array(B) resYList = Y.tolist() + Yt for i in range(len(resYList)): tableWidget.setItem( i, 257 + 8, QTableWidgetItem(str(round(Yn.tolist()[i], 4)))) tableWidget.setItem( i, 258 + 8, QTableWidgetItem( str( abs( round( round(resYList[i], 6) - round(Yn.tolist()[i], 6), 6)))))
def calculate_pfe(self): tableWidget = self.ui.tableWidget2 rows = tableWidget.rowCount() cols = tableWidget.columnCount() Xmin, Xmax = self.read_model_params() planningTable = [[ float(tableWidget.item(i, j).text()) for j in range(64) ] for i in range(rows)] factorMatrix = np.matrix( list(map(lambda row: row[1:7], planningTable.copy()))) checkVector = np.array(planningTable.copy()[-1][:64]) Y = [0 for i in range(9)] for i in range(len(factorMatrix.tolist())): la1 = convert_factor_to_value(Xmin[0], Xmax[0], float(factorMatrix.item((i, 0)))) dla1 = convert_factor_to_value(Xmin[1], Xmax[1], float(factorMatrix.item((i, 1)))) la2 = convert_factor_to_value(Xmin[2], Xmax[2], float(factorMatrix.item((i, 2)))) dla2 = convert_factor_to_value(Xmin[3], Xmax[3], float(factorMatrix.item((i, 3)))) mu = convert_factor_to_value(Xmin[4], Xmax[4], float(factorMatrix.item((i, 4)))) dmu = convert_factor_to_value(Xmin[5], Xmax[5], float(factorMatrix.item((i, 5)))) mT11, dT11, mT12, dT12, mT2, dT2 = calculate_params( la1, dla1, la2, dla2, mu, dmu) model = modeller.Model([mT11, mT12], [dT11, dT12], mT2, dT2, 2, 1, 0) avg_queue_size, avg_queue_time, processed_requests = model.time_based_modelling( 100, 0.001) Y[i] = avg_queue_time tableWidget.setItem( i, 64, QTableWidgetItem(str(round(avg_queue_time, 4)))) Yt = [Y[-1]] Y = np.array(Y[:-1]) B = [ np.array( [float(planningTable[i][k]) / len(Y) for i in range(len(Y))]) @ Y for k in range(64) ] Yl = np.array( list( map(lambda row: row[:7], planningTable + [checkVector.tolist()]))) @ np.array(B[:7]) Bl = B[:7] + [0 for i in range(7, len(B))] Bpn = B.copy() for i in range(0, 64): B[i] = B[i] / self.count_eq_rows(planningTable, i, len(planningTable[0])) y2 = ("y = %.6fb0 + %.6fb1 + %.6fb2 + %.6fb3 + %.6fb4 + %.6fb5 + %.6fb6" % \ (B[0], B[1], B[2], B[3], B[4], B[5], B[6])) y2 = str(y2) y2 = y2.replace("+ -", "- ") self.equ2.setText(y2) y3 = ("y = %.6fb0 + %.6fb1 + %.6fb2 + %.6fb3 + %.6fb4 + %.6fb5 + %.6fb6 + %.6fb12 + %.6fb13 + %.6fb14 " "+ %.6fb15 + %.6fb16 + %.6fb23 + %.6fb24 + %.6fb25 + %.6fb26 + %.6fb34 + %.6fb35 + %.6fb36 + %.6fb45 " "+ %.6fb46 + %.6fb56 + %.6fb123 + %.6fb124 + %.6f125 + %.6fb126 + %.6fb134 + %.6fb135 + %.6fb136 " "+ %.6fb145 + %.6fb146 + %.6fb156 + %.6fb234 + %.6fb235 + %.6fb236 + %.6fb245 + %.6fb246 + %.6fb256 " "+ %.6fb345 + %.6fb346 + %.6fb356 + %.6fb456 + %.6fb1234 + %.6fb1235 + %.6fb1236 + %.6fb1245 + %.6fb1246 " "+ %.6fb1256 + %.6fb1345 + %.6fb1346 + %.6fb1356 + %.6fb1456 + %.6fb2345 + %.6fb2346+ %.6fb2356 " "+ %.6fb2456 + %.6fb3456 + %.6fb12345 + %.6fb12346 + %.6fb12356 + %.6fb12456 + %.6fb13456 + %.6fb23456 " "+ %.6fb123456" % \ (B[0], B[1], B[2], B[3], B[4], B[5], B[6], B[7], B[8], B[9], B[10], B[11], B[12], B[13], B[14], B[15], B[16], B[17], B[18], B[19], B[20], B[21], B[22], B[23], B[24], B[25], B[26], B[27], B[28], B[29], B[30], B[31], B[32], B[33], B[34], B[35], B[36], B[37], B[38], B[39], B[40], B[41], B[42], B[43], B[44], B[45], B[46], B[47], B[48], B[49], B[50], B[51], B[52], B[53], B[54], B[55], B[56], B[57], B[58], B[59], B[60], B[61], B[62], B[63])) y3 = str(y3) y3 = y3.replace("+ -", "- ") self.equ3.setText(y3) for i in range(0, 22): Bpn[i] = Bpn[i] / self.count_eq_rows(planningTable, i, 22) for i in range(22, 64): Bpn[i] = 0 Ypn = np.array(planningTable + [checkVector.tolist()]) @ np.array(Bpn) resYList = Y.tolist() + Yt for i in range(len(resYList)): tableWidget.setItem( i, 65, QTableWidgetItem(str(round(Yl.tolist()[i], 4)))) tableWidget.setItem( i, 66, QTableWidgetItem(str(round(Ypn.tolist()[i], 4)))) tableWidget.setItem( i, 67, QTableWidgetItem( str( abs( round( round(resYList[i], 6) - round(Yl.tolist()[i], 6), 6))))) tableWidget.setItem( i, 68, QTableWidgetItem( str( abs( round( round(resYList[i], 6) - round(Ypn.tolist()[i], 6), 6)))))
def on_process(self): print('process') print(self.ui.layout.rowCount()) la = 0 dla = 1 mu = 0 dmu = 1 tmax = 300 for i in range(self.ui.layout.rowCount()): for j in range(self.ui.layout.columnCount()): if self.ui.layout.itemAtPosition(i, j): widget = self.ui.layout.itemAtPosition(i, j).widget() objName = widget.objectName() if not isinstance(widget, QLineEdit): continue try: if objName == 'arriveIntensity': print('arrive') la = float(widget.text()) elif objName == 'processIntensity': print('process') mu = float(widget.text()) elif objName == 'arriveIntensityDispersion': print('arrive disp') dla = float(widget.text()) elif objName == 'processIntensityDispersion': print('process disp') dmu = float(widget.text()) elif objName == 'modellingTime': print('time') tmax = float(widget.text()) except ValueError: QMessageBox.warning(self, 'Error', 'Ошибка ввода') return if (la <= 0 or dla >= la) or (mu <= 0 or dmu >= mu): QMessageBox.warning(self, 'Error', 'Интенсивности должны быть больше 0') return mT1, dT1, mT2, dT2 = calculate_params(la, dla, mu, dmu) model = modeller.Model(mT1, dT1, mT2, dT2, 1, 1, 0) print('start') ro = la / mu avg_queue_size, avg_queue_time, processed_requests = model.time_based_modellingg( tmax, 0.001) result = f'Расчетная загрузка системы: {ro}\n' \ f'Среднее количество заявок в системе: {avg_queue_size}\n' \ f'Среднее время ожидания: {avg_queue_time}\n' \ f'Обработано заявок: {processed_requests}' QMessageBox.information(self, 'Result', result) x, y = calculate_model_for_graph(calculate_params, 0.05, 0.01) show_plot(x, y) x, y = calculate_model_for_graph(calculate_params, 0.05, 0.1) show_plot(x, y) x, y = calculate_model_for_graph(calculate_params, 0.05, 0.5) show_plot(x, y) x, y = calculate_model_for_graph(calculate_params, 0.05, 1) show_plot(x, y)
from __future__ import print_function import modeller import mdt import mdt.features # Setup of Modeller and MDT system env = modeller.Environ() mlib = mdt.Library(env) # Creation of feature types restyp = mdt.features.ResidueType(mlib) # Create a 1D table of residue type table = mdt.Table(mlib, features=restyp) # Read in a PDB file and make an alignment of just this one structure mdl = modeller.Model(env, file='5fd1') aln = modeller.Alignment(env) aln.append_model(mdl, align_codes='5fd1', atom_files='5fd1') # Collect MDT statistics for this alignment table.add_alignment(aln) # Print out the MDT by treating it as a Python list print("Distribution of residue types:") print([bin for bin in table])
def on_calculate_model(self): layout = self.ui.externalLayout.itemAt(1) tableWidget = self.ui.tableWidget rows = tableWidget.rowCount() cols = tableWidget.columnCount() Xmin, Xmax = self.read_model_params() # print(Xmin, Xmax) planningTable = [[tableWidget.item(i, j).text() for j in range(cols)] for i in range(rows)] coefMatrix, planningMatrix, checkVector = process_matrixes(planningTable) factorMatrix = np.matrix(list(map(lambda row: row[1:5], planningTable.copy()))) Y = [0 for i in range(17)] # print(factorMatrix) for i in range(len(factorMatrix.tolist())): # la = 0 # mu = 0 # dla = 0 # dmu = 0 # if round(float(factorMatrix.item((i, 0)))) == 1: # la = Xmax[0] # else: # la = Xmin[0] # if round(float(factorMatrix.item((i, 1)))) == 1: # dla = Xmax[1] # else: # dla = Xmin[1] # if round(float(factorMatrix.item((i, 2)))) == 1: # mu = Xmax[2] # else: # mu = Xmin[2] # if round(float(factorMatrix.item((i, 3)))) == 1: # dmu = Xmax[3] # else: # dmu = Xmin[3] la = convert_factor_to_value(Xmin[0], Xmax[0], float(factorMatrix.item((i, 0)))) dla = convert_factor_to_value(Xmin[1], Xmax[1], float(factorMatrix.item((i, 1)))) mu = convert_factor_to_value(Xmin[2], Xmax[2], float(factorMatrix.item((i, 2)))) dmu = convert_factor_to_value(Xmin[3], Xmax[3], float(factorMatrix.item((i, 3)))) # print(la, dla, mu, dmu) mT1, dT1, mT2, dT2 = calculate_params(la, dla, mu, dmu) model = modeller.Model(mT1, dT1, mT2, dT2, 1, 1, 0) avg_queue_size, avg_queue_time, processed_requests = model.time_based_modellingg(100, 0.001) # print(avg_queue_time) Y[i] = avg_queue_time tableWidget.setItem(i, 16, QTableWidgetItem(str(round(avg_queue_time, 4)))) Yt = [Y[-1]] Y = np.array(Y[:-1]) print("calculated") B = (coefMatrix @ Y).tolist()[0] self.set_b_table(B) # print(B[:5]) Yl = np.array(list(map(lambda row: row[:5], planningMatrix.tolist() + [checkVector.tolist()]))) @ np.array(B[:5]) Ypn = np.array(planningMatrix.tolist() + [checkVector.tolist()]) @ np.array(B) resYList = Y.tolist() + Yt for i in range(len(resYList)): tableWidget.setItem(i, 17, QTableWidgetItem(str(round(Yl.tolist()[i], 4)))) tableWidget.setItem(i, 18, QTableWidgetItem(str(round(Ypn.tolist()[i], 4)))) tableWidget.setItem(i, 19, QTableWidgetItem( str(abs(round(round(resYList[i], 6) - round(Yl.tolist()[i], 6), 6))))) tableWidget.setItem(i, 20, QTableWidgetItem( str(abs(round(round(resYList[i], 6) - round(Ypn.tolist()[i], 6), 6)))))
def calculate_ffe(self): tableWidget = self.ui.tableWidget rows = tableWidget.rowCount() cols = tableWidget.columnCount() Xmin, Xmax = self.read_model_params() planningTable = [[tableWidget.item(i, j).text() for j in range(cols)] for i in range(rows)] coefMatrix, planningMatrix, checkVector = process_matrixes( planningTable) factorMatrix = np.matrix( list(map(lambda row: row[1:7], planningTable.copy()))) Y = [0 for i in range(65)] for i in range(len(factorMatrix.tolist())): la1 = convert_factor_to_value(Xmin[0], Xmax[0], float(factorMatrix.item((i, 0)))) dla1 = convert_factor_to_value(Xmin[1], Xmax[1], float(factorMatrix.item((i, 1)))) la2 = convert_factor_to_value(Xmin[2], Xmax[2], float(factorMatrix.item((i, 2)))) dla2 = convert_factor_to_value(Xmin[3], Xmax[3], float(factorMatrix.item((i, 3)))) mu = convert_factor_to_value(Xmin[4], Xmax[4], float(factorMatrix.item((i, 4)))) dmu = convert_factor_to_value(Xmin[5], Xmax[5], float(factorMatrix.item((i, 5)))) mT11, dT11, mT12, dT12, mT2, dT2 = calculate_params( la1, dla1, la2, dla2, mu, dmu) model = modeller.Model([mT11, mT12], [dT11, dT12], mT2, dT2, 2, 1, 0) avg_queue_size, avg_queue_time, processed_requests = model.time_based_modelling( 100, 0.001) Y[i] = avg_queue_time tableWidget.setItem( i, 64, QTableWidgetItem(str(round(avg_queue_time, 4)))) Yt = [Y[-1]] Y = np.array(Y[:-1]) B = (coefMatrix @ Y).tolist()[0] y0 = ("y = %.6fb0 + %.6fb1 + %.6fb2 + %.6fb3 + %.6fb4 + %.6fb5 + %.6fb6" % \ (B[0], B[1], B[2], B[3], B[4], B[5], B[6])) y0 = str(y0) y0 = y0.replace("+ -", "- ") self.equ0.setText(y0) y1 = ("y = %.6fb0 + %.6fb1 + %.6fb2 + %.6fb3 + %.6fb4 + %.6fb5 + %.6fb6 + %.6fb12 + %.6fb13 + %.6fb14 " "+ %.6fb15 + %.6fb16 + %.6fb23 + %.6fb24 + %.6fb25 + %.6fb26 + %.6fb34 + %.6fb35 + %.6fb36 + %.6fb45 " "+ %.6fb46 + %.6fb56 + %.6fb123 + %.6fb124 + %.6f125 + %.6fb126 + %.6fb134 + %.6fb135 + %.6fb136 " "+ %.6fb145 + %.6fb146 + %.6fb156 + %.6fb234 + %.6fb235 + %.6fb236 + %.6fb245 + %.6fb246 + %.6fb256 " "+ %.6fb345 + %.6fb346 + %.6fb356 + %.6fb456 + %.6fb1234 + %.6fb1235 + %.6fb1236 + %.6fb1245 + %.6fb1246 " "+ %.6fb1256 + %.6fb1345 + %.6fb1346 + %.6fb1356 + %.6fb1456 + %.6fb2345 + %.6fb2346+ %.6fb2356 " "+ %.6fb2456 + %.6fb3456 + %.6fb12345 + %.6fb12346 + %.6fb12356 + %.6fb12456 + %.6fb13456 + %.6fb23456 " "+ %.6fb123456" % \ (B[0], B[1], B[2], B[3], B[4], B[5], B[6], B[7], B[8], B[9], B[10], B[11], B[12], B[13], B[14], B[15], B[16], B[17], B[18], B[19], B[20], B[21], B[22], B[23], B[24], B[25], B[26], B[27], B[28], B[29], B[30], B[31], B[32], B[33], B[34], B[35], B[36], B[37], B[38], B[39], B[40], B[41], B[42], B[43], B[44], B[45], B[46], B[47], B[48], B[49], B[50], B[51], B[52], B[53], B[54], B[55], B[56], B[57], B[58], B[59], B[60], B[61], B[62], B[63])) y1 = str(y1) y1 = y1.replace("+ -", "- ") self.equ1.setText(y1) Yl = np.array( list( map(lambda row: row[:7], planningMatrix.tolist() + [checkVector.tolist()]))) @ np.array(B[:7]) Ypn = np.array(planningMatrix.tolist() + [checkVector.tolist()]) @ np.array(B) resYList = Y.tolist() + Yt for i in range(len(resYList)): tableWidget.setItem( i, 65, QTableWidgetItem(str(round(Yl.tolist()[i], 4)))) tableWidget.setItem( i, 66, QTableWidgetItem(str(round(Ypn.tolist()[i], 4)))) tableWidget.setItem( i, 67, QTableWidgetItem( str( abs( round( round(resYList[i], 6) - round(Yl.tolist()[i], 6), 6))))) tableWidget.setItem( i, 68, QTableWidgetItem( str( abs( round( round(resYList[i], 6) - round(Ypn.tolist()[i], 6), 6)))))