def run(configx): """ Entry point for the plugin manager :param configx: plugin manager instance :return: None """ global config, data config = configx printer = config.setup() pdbiop = PDBIOP('test.test') pdbiop.setup(new=True) data = config.get_variable() pdbiop.set(['cart', 'serial_numbers', 'name_prefixes', 'occupancies', 'adp_cart', 'residue_numbers', 'vdw_radii', 'point_charges'], provide, new=True) printer(pdbiop.export('PQR')) with open(config.arg('write'), 'w') as fp: fp.write(pdbiop.export('PQR')) printer('\nPQR formatted output written to {}.'.format(config.arg('write')))
def report(accumulator): """ Compiles a table representing the data analysis results and prints it to the output. """ printer('\n') length = int(config.arg('list')) gt = float(config.arg('gt')) resi = config.arg('residue') rtype = config.arg('type') sigma = float(config.arg('sigma')) sorted_atoms = sorted(accumulator.atoms(), key=lambda atom: atom.get_error_dist(), reverse=True) printer.table(['Type', 'ID', 'Resi', '#', 'ESD', 'ESD: X Y Z', 'Average Position'], head=True) counter = 0 for atom in sorted_atoms: errors = '{:3.1f}'.format(atom.get_error_dist()) if gt: if not float(errors) >= gt: continue if resi: if not atom.get_residue() == resi: continue if rtype: if not atom.get_type() == rtype: continue xyz_err = '{:3.1f} {:3.1f} {:3.1f}'.format(*atom.get_error_cart()) position = '{:5.1f} {:5.1f} {:5.1f}'.format(*atom.get_cart()) printer.table([atom.get_type(), atom.get_serial_number(), atom.get_residue(), atom.get_residue_number(), errors, xyz_err, position]) counter += 1 if counter == length: break printer.table(done=True) def provideNew(): """ Generator providing data to a PDB file. """ for thisatom in sorted_atoms: if thisatom.get_error_dist() < cutoff: yield [thisatom.get_name(), thisatom.get_serial_number(), thisatom.get_type(), thisatom.get_residue(), thisatom.get_residue_number(), thisatom.get_cart(), thisatom.get_occupancy(), thisatom.get_adp_cart()] # printer('\n\n{} atoms removed.'.format(ko)) _mask = config.arg('mask') if not _mask: _mask = 'all' crosspdb = PDBIOP('{}_crosscheck.pdb'.format(_mask)) crosspdb.setup(new=True) crosspdb.set(['serial_numbers', 'name_prefixes', 'residues', 'residue_numbers', 'cart', 'occupancies', 'adp_cart'], provideNew, new=True) crosspdb.complete_rebuild() crosspdb.write() printer('\n\nAveraged PDB file without atoms with ESDs larger than {} written to:\n{}'.format(cutoff, '{}_crosscheck.pdb'.format(_mask)))
def run(conf): global config config = conf printer = config.setup() printer('\nThe resp_pqr_plugin has been successfully started.\n' \ 'Now, resp-charges are assigned according to their invariom name.' \ '\nIn order to do this a file called chargeDABA.txt \ncontaining all invariomnames with' \ 'the correcponding resp charges is needed.\n') printer('\nAsking config for value of option \'load\': {}'.format(config.arg('load'))) printer('Asking config for value of option \'x\': {}'.format(config.arg('x'))) import lauescript.invstring2 as invstring config.call('applyhdist') ###--------reading chargeDABA.txt into dictionary chargedict ---------------# path_string = conf.get_databasepath() global chargedict chargedict = {} f = open(path_string + '/chargeDABA.txt', 'r') for line in f.readlines(): line = line[:-1].split() chargedict[line[0]] = float(line[1]) f.close() ###---------------------- ###--------molecule identifier ---------------# global molcount molcount=0 global chargedicts chargedicts = {} global resp_arrays resp_arrays = {} global atomcounts atomcounts = {} global average_charges average_charges = {} data = config.get_variable() for atom in data['exp'].atoms: if atom.molecule_id > molcount: molcount = atom.molecule_id resp_arrays[atom.molecule_id]= [] molcount=molcount+1 printer('{} molecule(s) detected.'.format(molcount)) for j in range(0,molcount): resp_arrays[j] = [] atomcounts[j] = 0 average_charges[j] = 0.0 chargedicts[j]={} for atom in data['exp'].atoms: atomcounts[atom.molecule_id] = atomcounts[atom.molecule_id] + 1 ###---------------------- global average_corrections average_corrections = {} overallcharges = {} resp = 0.0 charged=config.arg("charged") import charge_lib for j in range(0,molcount): overallcharges[j]=0.0 overallcharges[j]=charge_lib.check_charges(j, atomcounts, charged, printer ) ### Electroneutrality correction ###-------------collecting charges for the molecule ###-------------to get a correction factor for electroneutrality ### ----Option a ###-------------via a correction averaged over the whole molecule neutral = config.arg("neutral") if not neutral or neutral == "a": printer(neutral) for atom in data['exp'].atoms: import charge_lib charge_lib.build_resp_arrays( atom, resp_arrays, chargedict, average_charges) for key in resp_arrays: printer('\nMolecule number {}:'.format(key)) printer('Number of atoms read: {}'.format(atomcounts[key])) #printer('\nCharges of the invarioms') #printer(resp_array) printer('Charge of molecule if uncorrected: {:5.3f}'.format(sum(resp_arrays[key]))) printer('Deviation from charge of {:5.3f}: {:5.3f}'.format(overallcharges[key],sum(resp_arrays[key])-overallcharges[key])) average_corrections[key] = float(float((sum(resp_arrays[key])-overallcharges[key])) / float(atomcounts[key])) printer('Correction for every atom: {:5.3f}'.format(average_corrections[key])) printer('Average charge per atom: {:5.3f}, correction in percent: {:5.2f}%'.format(average_charges[key]/atomcounts[key],100*average_corrections[key]/(average_charges[key]/atomcounts[key]))) ### Assigning charge #print '\natom elec val_elec invariom resp_charge corr_charge\n' #i = 0 already_corrected_inv_list = [] data = config.get_variable() for atom in data['exp'].atoms: if atom.molecule_id == key : #i = i + 1 resp = chargedict[atom.invariom_name] if atom.invariom_name not in already_corrected_inv_list: charge = resp - average_corrections[key] #chargedict[atom.invariom_name] = charge already_corrected_inv_list.append(atom.invariom_name) chargedicts[key][atom.invariom_name] = charge else: charge = resp- average_corrections[key] #resp = charge + average_corrections[key] #print atom.name, atom.invariom_name, resp, charge ### ----Option b ###-------------via a correction averaged all hydrogen atoms only elif neutral == "b": printer(neutral) data = config.get_variable() Hatomcounts = {} for j in range(0,molcount): Hatomcounts[j] = 0 for atom in data['exp'].atoms: if atom.element == "H": Hatomcounts[atom.molecule_id] = Hatomcounts[atom.molecule_id] + 1 import charge_lib charge_lib.build_resp_arrays( atom, resp_arrays, chargedict, average_charges) for key in resp_arrays: printer(key) printer('\nNumber of H atoms read:') printer(Hatomcounts[key]) printer('Charges of the invarioms') printer(resp_arrays[key]) printer('\nCharge of molecule if uncorrected:') printer(sum(resp_arrays[key])) printer('Deviation from charge of {}:'.format(overallcharges[key])) printer(sum(resp_arrays[key])-overallcharges[key]) average_corrections[key] = float(float((sum(resp_arrays[key])-overallcharges[key])) / float(Hatomcounts[key])) printer('Correction for every H atom:') printer(average_corrections[key]) printer('\nAverage charge per atom, correction in percent:') printer(average_charges[key]/Hatomcounts[key]) printer(average_corrections[key]/(average_charges[key]/Hatomcounts[key])) ### Assigning charge #print '\natom elec val_elec invariom resp_charge corr_charge\n' i = 0 already_corrected_inv_list = [] data = config.get_variable() for atom in data['exp'].atoms: if atom.molecule_id == key : i = i + 1 resp = chargedict[atom.invariom_name] if atom.element == "H": if atom.invariom_name not in already_corrected_inv_list: charge = resp - average_corrections[key] chargedicts[key][atom.invariom_name] = charge already_corrected_inv_list.append(atom.invariom_name) else: charge = resp - average_corrections[key] resp = charge else: charge = resp chargedicts[key][atom.invariom_name] = charge #print atom.name, atom.invariom_name, resp, charge ### ----------------------------------- ### ### Writing the charges into a pqr file ### ### ----------------------------------- from lauescript.laueio.pdb_iop import PDBIOP global data pdbiop = PDBIOP('test.test') pdbiop.setup(new=True) pdb_data = config.get_variable() pdbiop.set(['cart', 'serial_numbers', 'name_prefixes', 'occupancies', 'adp_cart', 'residue_numbers', 'vdw_radii', 'point_charges'], provide_pdb, new=True) #print pdbiop.export('PQR') text_file = open("resp.pqr", "w") ## ADD THE CRYST INSTRUCTUINS HERE text_file.write("CRYST1 {:6.4f} {:6.4f} {:6.4f} {:6.4f} {:6.4f} {:6.4f} \n".format(*data["exp"].get_cell())) text_file.write("%s" % pdbiop.export('PQR')) text_file.close() printer( '\n resp.pqr has been written, with the assigned resp charges and vdw radii according to J Phys Chem, 2009, p. 5806-5812.\n')