def get_qfac(protein_file, npc, res_num, q_fac_dict): """Fit and individual tensor to each model in the bundle and save each Q-factor into an universal dictionary""" # Load the protein, load the npc prot = protein.load_pdb(protein_file) rawData = dataparse.read_pcs(npc) qfactor_sep = {} # Initialize metal instance for search and set the initial position mStart = metal.Metal() mStart.position = prot[0]['A'][res_num]['CA'].position # Loop: for every model fit an individual tensor and store Q-factors and tensor components into a dict for model in prot: parsedData = prot.parse(rawData, models=model.id) [mGuess], _ = fit.svd_gridsearch_fit_metal_from_pcs([mStart], [parsedData], radius=10, points=10) [mFit], [data] = fit.nlr_fit_metal_from_pcs([mGuess], [parsedData]) qfactor_sep[model.id] = fit.qfactor(data) # Save in universal dictionary if type(q_fact_dict[model.id]) == list: q_fac_dict[model.id].append(fit.qfactor(data)) else: q_fac_dict[model.id] = [fit.qfactor(data)] minModel, minQfac = sorted(qfactor_sep.items(), key=lambda x: x[1])[0]
def get_tensor(protein_file, model, npc, res_num, tag_number): """Fit a tensor only to the specified model of the bundle pdb and writes down the corresponding components and ORI""" # Load the protein, load the npc prot = protein.load_pdb(protein_file) rawData = dataparse.read_pcs(npc) # Initialize metal instance for search and set the initial position mStart = metal.Metal() mStart.position = prot[model]['A'][res_num]['CA'].position # Get tensor on single structure for mod in prot: if mod.id == model: parsedData = prot.parse(rawData, models=mod.id) [mGuess], [data ] = fit.svd_gridsearch_fit_metal_from_pcs([mStart], [parsedData], radius=10, points=10) [mFit], [data] = fit.nlr_fit_metal_from_pcs([mGuess], [parsedData]) Axial = round(mFit.ax * 1E32, 3) Rhombicity = round((mFit.rh / mFit.ax), 3) # Generate .pcs metal center file name = os.path.splitext(protein_file)[0] + "_metal_centers.pcs" f = open(name, 'a+') f.write(5 * " " + str(tag_number) + (14 - len(str(Axial))) * " " + str(Axial) + "E+04 " + str(Rhombicity) + 5 * " " + str(Tag_dictionary[tag_number]) + "\n") # Extract information about the metal center position relative to the protein backbone and write them ori = mFit.position name_ori_upl = os.path.splitext(protein_file)[0] + "_ORI_UPL.upl" name_ori_lol = os.path.splitext(protein_file)[0] + "_ORI_LOL.lol" u = open(name_ori_upl, 'a+') l = open(name_ori_lol, 'a+') for res_num in Ori_dictionary[tag_number]: res = prot[model]['A'][res_num]['CA'].position res_type = prot[model]['A'][res_num].get_resname() d = math.sqrt(((ori[0] - res[0])**2) + ((ori[1] - res[1])**2) + ((ori[2] - res[2])**2)) d_upl = round((d * 1E10) + 0.5, 2) d_lol = round((d * 1E10) - 0.5, 2) u.write((3 - len(str(res_num))) * " " + str(res_num) + " " + res_type + " CA " + str(Tag_dictionary[tag_number]) + " ORI A0" + (10 - len(str(d_upl))) * " " + str(d_upl) + "\n") l.write((3 - len(str(res_num))) * " " + str(res_num) + " " + res_type + " CA " + str(Tag_dictionary[tag_number]) + " ORI A0" + (10 - len(str(d_lol))) * " " + str(d_lol) + "\n")
from paramagpy import protein, fit, dataparse, metal import numpy as np # Load the PDB file prot = protein.load_pdb('../data_files/2bcb.pdb') # Load the PCS data rawData = dataparse.read_pcs('../data_files/calbindin_Er_HN_PCS_errors.npc') # Associate PCS data with atoms of the PDB parsedData = prot.parse(rawData) # Define an initial tensor mStart = metal.Metal() # Set the starting position to an atom close to the metal mStart.position = prot[0]['A'][56]['CA'].position # Calculate an initial tensor from an SVD gridsearch [mGuess], [data] = fit.svd_gridsearch_fit_metal_from_pcs([mStart], [parsedData], radius=10, points=10) # Refine the tensor using non-linear regression [mFit], [data] = fit.nlr_fit_metal_from_pcs([mGuess], [parsedData]) # Estimate uncertainty sourcing noise from the models of the PDB [mod_all], [mod_std] = fit.fit_error_models(fit.nlr_fit_metal_from_pcs, initMetals=[mFit], dataArrays=[parsedData])
} pmlscript = protein.PyMolScript() pmlscript.add_pdb(path=pdb_path, name='5ev6') mdata = [] for site in sites: # Loop over sites bindingSite = int(re.search("\\d+", site).group()) # Get residue number mStart = metal.Metal() mStart.position = prot[0]['A'][bindingSite][ 'CA'].position # Set strating position hnpcss = [] # Assemble exp. PCS data for both ions for ion in ions: hnpcs_raw = dataparse.read_pcs( "../data_files/IMP1_HN_{}_{}_FREE.npc".format(site, ion)) hnpcs = prot.parse(hnpcs_raw) hnpcss.append(hnpcs) # Fit the tensor by SVD, then NLR mGuess, _ = fit.svd_gridsearch_fit_metal_from_pcs([mStart, mStart], hnpcss) mFit, _ = fit.nlr_fit_metal_from_pcs(mGuess, hnpcss) # Sample purturbed tensors by bootstrap mSamples, mStd = fit.fit_error_bootstrap(fit.nlr_fit_metal_from_pcs, BOOTSTRAP_ITER, 0.8, initMetals=mFit, dataArrays=hnpcss) mdata.append(mSamples)
from paramagpy import protein, fit, dataparse, metal # Load the PDB file prot = protein.load_pdb('../data_files/4icbH_mut.pdb') # Load the PCS data rawData1 = dataparse.read_pcs('../data_files/calbindin_Tb_HN_PCS.npc') rawData2 = dataparse.read_pcs('../data_files/calbindin_Er_HN_PCS.npc') rawData3 = dataparse.read_pcs('../data_files/calbindin_Yb_HN_PCS.npc') # Associate PCS data with atoms of the PDB parsedData = [] for rd in [rawData1, rawData2, rawData3]: parsedData.append(prot.parse(rd)) # Make a list of starting tensors mStart = [metal.Metal(), metal.Metal(), metal.Metal()] # Set the starting position to an atom close to the metal mStart[0].position = prot[0]['A'][56]['CA'].position # Calculate initial tensors from an SVD gridsearch mGuess = fit.svd_gridsearch_fit_metal_from_pcs(mStart, parsedData, radius=10, points=10) # Refine the tensors using non-linear regression fitParameters = ['x', 'y', 'z', 'ax', 'rh', 'a', 'b', 'g'] mFit = fit.nlr_fit_metal_from_pcs(mGuess, parsedData, fitParameters)
BACK_CALCULATED_PCS_FILE_NAME = 'pcscal.npc' CORRELATION_PLOT = True CORRELATION_PLOT_FILE_NAME = "pcs_fit.png" CORRELATION_PLOT_ANNOTATE = False PYMOL_ISOSURFACE = True from paramagpy import protein, fit, dataparse, metal import sys, subprocess expPCS_fileName = sys.argv[1] # Load the PDB file prot = protein.load_pdb(PDB_FILE) # Load the PCS data rawData = dataparse.read_pcs(expPCS_fileName) # Associate PCS data with atoms of the PDB parsedData = prot.parse(rawData) # Define an initial tensor mStart = metal.Metal() # Set the starting position to an atom close to the metal mStart.position = prot[0]['A'][START_ATOM[0]][START_ATOM[1]].position # Calculate an initial tensor from an SVD gridsearch mGuess, calc, qfac = fit.svd_gridsearch_fit_metal_from_pcs( [mStart], [parsedData], radius=SVD_RADIUS, points=int(SVD_RADIUS / SVD_DENSITY))