예제 #1
0
파일: tasks.py 프로젝트: isaxs/sct
def get_box_opt_input(pdb_filename, *args):
    """
    Get the target volume and atomic coordinates for box_side optimization. If
    specified use a sequence other than that of the input PDB providing the
    coordinates.
    @type  pdb_filename: string
    @param pdb_filename: Path to PDB file
    @type  *args:        list
    @param *args:        Allow entry of sequence files path and format.
                         Format is either fasta ('fas') or YAML ('yml')
    @rtype:              float, float, list
    @return:             1. Target unhydrated volume from sequence

                         2. Target hydrated volume from sequence

                         3. A list containing lists of x, y & z coordinates
                         (3 * floats)
    """

    try:
        seq_filename = args[0]
        seq_type = args[1]
    except:
        seq_filename = None
        seq_type = None

    # Read in the residues frequencies (to calculate target volume) and
    # atomic coordinates from input PDB
    res_freq, atom_coords = pdb.read_pdb_atom_data(pdb_filename)

    # If an additional sequence file was provided then use this as the sequence
    # to optimize
    if seq_type is not None:
        res_freq = seq.seq_file_to_freq(seq_filename, seq_type)

    dry_volume = seq.sum_volume(seq.all_residues,
                                res_freq, 'perkins1986a')
    # Calculate the expected volume of the hydration layer
    # Hydration is estimated to be 0.3 g water per 1 g protein
    # Bound water volume (< bulk volume) is given as a sluv parameter
    wet_volume = seq.calc_hydration_volume(res_freq) + dry_volume

    return dry_volume, wet_volume, atom_coords
예제 #2
0
파일: tasks.py 프로젝트: isaxs/sct
def perform_sas_analysis_pdb(
        pdb_file,
        neut_data,
        xray_data,
        param,
        out_paths,
        chi2=False):
    """
    Create sphere models from PDBs and use to generate theoretical scattering
    curves and compare these to experimental inputs

    @type  pdb_file:   string
    @param pdb_file:   Filename of the input PDB
    @type  neut_data:  list
    @param neut_data:  List of numpy arrays with two columns (Q and I)
                       containing neutron experimental data
    @type  xray_data:  list
    @param xray_data:  List of numpy arrays with two columns (Q and I)
                       containing xray experimental data
    @type  param:      dictionary
    @param param:      Dictionary containing parameters to use when creating
                       models and analysing curves.
    @type  radius:     float
    @param radius:     Radius of spheres to be used in sphere models
    @type  chi2:       boolean
    @param chi2:       Use Chi^2 instead of R factor as curve comparison metric

    @rtype:            dictionary, dictionary
    @return:           Dictionaries containing the following key/value pairs
                       for the dry model/neutron and wet model/xray
                       comparisons:

                       model_rg: Radius of gyration calculated directly
                       from sphere model.

                       curve_rg: Radius of gyration calculated from the
                       theoretical scattering curve derived from the sphere
                       model.

                       curve_rxs1: Cross-section calculated from the
                       theoretical scattering curve derived from the sphere
                       model.

                       rfac: R factor comparing experimental and
                       theoretical scattering curves.

                       volume: Sphere model volume
    """

    cutoff = param['sphere']['cutoff']
    box_side = param['sphere']['boxside']
    box_side3 = param['sphere']['boxside3']
    radius = param['sphere']['radius']

    pdb_basename = os.path.basename(pdb_file)
    pdb_id = os.path.splitext(pdb_basename)[0]

    # Read PDB
    res_freq, atom_coords = pdb.read_pdb_atom_data(pdb_file)

    if len(atom_coords) > 0:

        # PDB to dry sphere model
        dry_spheres, x_axis, y_axis, z_axis = sphere.create_sphere_model(
            atom_coords, cutoff, box_side)

        # If neutron data provided compare with curve computed from dry sphere
        # model
        if len(neut_data) != 0:

            neut_theor = analyse_sphere_model(
                dry_spheres,
                neut_data,
                radius,
                param,
                chi2,
                True)

            # Write curve to file
            curve_file = os.path.join(out_paths['scn'], pdb_id + '.scn')
            curve.output_sas_curve(neut_theor['curve'], curve_file)

            # Write model to file
            model_file = os.path.join(out_paths['dry_model'], pdb_id + '.pdb')
            pdb.write_sphere_pdb(dry_spheres, radius, model_file)

            neut_theor['volume'] = box_side3 * len(dry_spheres)

        else:
            neut_theor = {}

        # If x-ray data provided compare with curve computed from wet sphere
        # model
        if len(xray_data) != 0:
            # Hydrate model - > wet sphere model
            wet_spheres = sphere.hydrate_sphere_model(
                dry_spheres,
                param['hydrate']['positions'],
                box_side,
                param['hydrate']['cutoff'],
                xaxis=x_axis,
                yaxis=y_axis,
                zaxis=z_axis)

            xray_theor = analyse_sphere_model(
                wet_spheres,
                xray_data,
                radius,
                param,
                chi2)

            # Write curve to file
            curve_file = os.path.join(out_paths['scx'], pdb_id + '.scx')
            curve.output_sas_curve(xray_theor['curve'], curve_file)

            # Write model to file
            model_file = os.path.join(out_paths['wet_model'], pdb_id + '.pdb')
            pdb.write_sphere_pdb(wet_spheres, radius, model_file)

            xray_theor['volume'] = box_side3 * len(wet_spheres)

        else:
            xray_theor = {}

        return neut_theor, xray_theor