Ejemplo n.º 1
0
def _conf_to_spsim_opts(D_source,D_particle,D_detector):
    import spsim
    # Create temporary file for pdb file
    tmpf_pdb = tempfile.NamedTemporaryFile(mode='w+b', bufsize=-1, suffix='.conf', prefix='tmp_spsim', dir=None, delete=False)
    tmpf_pdb_name = tmpf_pdb.name
    tmpf_pdb.close()
    # Write pdb file
    mol = spsim.get_molecule_from_atoms(D_particle["atomic_numbers"], D_particle["atomic_positions"])
    spsim.write_pdb_from_mol(tmpf_pdb_name, mol)
    spsim.free_mol(mol)
    # Start with default spsim configuration
    opts = spsim.set_defaults()
    # Create temporary file for spsim configuration
    tmpf_conf = tempfile.NamedTemporaryFile(mode='w+b', bufsize=-1, suffix='.conf', prefix='tmp_spsim', dir=None, delete=False)
    # Write string sequence from configuration dicts
    s = []
    s += "# THIS FILE WAS CREATED AUTOMATICALLY BY CONDOR\n"
    s += "# Temporary configuration file for spsim\n"
    s += "verbosity_level = 0;\n"
    s += "number_of_dimensions = 2;\n"
    s += "number_of_patterns = 1;\n"
    s += "origin_to_com = 1;\n"
    s += "input_type = \"pdb\";\n"
    #s += "pdb_filename = \"%s\";\n" % D_particle["pdb_filename"]
    s += "pdb_filename = \"%s\";\n" % tmpf_pdb_name
    s += "detector_distance = %.6e;\n" % D_detector["distance"]
    s += "detector_width = %.6e;\n" % (D_detector["pixel_size"] * D_detector["nx"]) 
    s += "detector_height = %.6e;\n" % (D_detector["pixel_size"] * D_detector["ny"])
    s += "detector_pixel_width = %.6e;\n" % D_detector["pixel_size"]
    s += "detector_pixel_height = %.6e;\n" % D_detector["pixel_size"]
    s += "detector_center_x = %.6e;\n" % (D_detector["pixel_size"] * (D_detector["cx"] - (D_detector["nx"]-1)/2.))
    s += "detector_center_y = %.6e;\n" % (D_detector["pixel_size"] * (D_detector["cy"] - (D_detector["ny"]-1)/2.))
    s += "detector_binning = 1;\n"
    s += "experiment_wavelength = %.6e;\n" % D_source["wavelength"]
    s += "experiment_beam_intensity = %.6e;\n" % D_particle["intensity"]
    #s += "use_cuda = 0;\n"
    intrinsic_rotation = condor.utils.rotation.Rotation(values=D_particle["extrinsic_quaternion"],formalism="quaternion")
    intrinsic_rotation.invert()
    e0, e1, e2 = intrinsic_rotation.get_as_euler_angles("zxz")
    s += "phi = %.6e;\n" % e0
    s += "theta = %.6e;\n" % e1
    s += "psi = %.6e;\n" % e2
    s += "random_orientation = 0;\n"
    # Write string sequence to file
    tmpf_conf.writelines(s)
    # Close temporary file
    tmpf_conf_name = tmpf_conf.name
    tmpf_conf.close()
    # Read configuration into options struct
    spsim.read_options_file(tmpf_conf_name, opts)
    # This deletes the temporary files
    os.unlink(tmpf_pdb_name)
    os.unlink(tmpf_conf_name)
    return opts
Ejemplo n.º 2
0
    def set_atoms_from_pdb_file(self, pdb_filename):
        """
        Specify atomic positions from a PDB file 

        The PDB file format is described here: `http://www.wwpdb.org/documentation/file-format <http://www.wwpdb.org/documentation/file-format>`

        Args:
          :pdb_filename (str): Location of the PDB file
        """
        import spsim
        mol = spsim.get_Molecule_from_pdb(pdb_filename)
        self._atomic_numbers, self._atomic_positions = spsim.get_atoms_from_molecule(mol)
        spsim.free_mol(mol)
Ejemplo n.º 3
0
    def set_atoms_from_pdb_file(self, pdb_filename):
        """
        Specify atomic positions from a PDB file 

        The PDB file format is described here: `http://www.wwpdb.org/documentation/file-format <http://www.wwpdb.org/documentation/file-format>`

        Args:
          :pdb_filename (str): Location of the PDB file
        """
        import spsim
        mol = spsim.get_Molecule_from_pdb(pdb_filename)
        self._atomic_numbers, self._atomic_positions = spsim.get_atoms_from_molecule(
            mol)
        spsim.free_mol(mol)
Ejemplo n.º 4
0
def _conf_to_spsim_opts(D_source,
                        D_particle,
                        D_detector,
                        ndim=2,
                        qn=None,
                        qmax=None):
    if ndim == 2:
        if qn is not None or qmax is not None:
            log_warning(
                logger,
                "As ndim=2 the passed values for qn and qmax take no effect.")
    if ndim == 3:
        if qn is None and qmax is None:
            log_and_raise_error(
                logger, "As ndim=3 both qn and qmax must be not None.")
            return
    import spsim
    # Create temporary file for pdb file
    tmpf_pdb = tempfile.NamedTemporaryFile(mode='w+b',
                                           bufsize=-1,
                                           suffix='.conf',
                                           prefix='tmp_spsim',
                                           dir=None,
                                           delete=False)
    tmpf_pdb_name = tmpf_pdb.name
    tmpf_pdb.close()
    # Write pdb file
    mol = spsim.get_molecule_from_atoms(D_particle["atomic_numbers"],
                                        D_particle["atomic_positions"])
    spsim.write_pdb_from_mol(tmpf_pdb_name, mol)
    spsim.free_mol(mol)
    # Start with default spsim configuration
    opts = spsim.set_defaults()
    # Create temporary file for spsim configuration
    tmpf_conf = tempfile.NamedTemporaryFile(mode='w+b',
                                            bufsize=-1,
                                            suffix='.conf',
                                            prefix='tmp_spsim',
                                            dir=None,
                                            delete=False)
    # Write string sequence from configuration dicts
    s = []
    s += "# THIS FILE WAS CREATED AUTOMATICALLY BY CONDOR\n"
    s += "# Temporary configuration file for spsim\n"
    s += "verbosity_level = 0;\n"
    s += "number_of_dimensions = %i;\n" % ndim
    s += "number_of_patterns = 1;\n"
    s += "origin_to_com = 1;\n"
    s += "input_type = \"pdb\";\n"
    #s += "pdb_filename = \"%s\";\n" % D_particle["pdb_filename"]
    s += "pdb_filename = \"%s\";\n" % tmpf_pdb_name
    if ndim == 2:
        D = D_detector["distance"]
        Lx = D_detector["pixel_size"] * D_detector["nx"]
        Ly = D_detector["pixel_size"] * D_detector["ny"]
    else:
        k0 = 2. * numpy.pi / D_source["wavelength"]
        D = qn / 2. * D_detector["pixel_size"] * k0 / qmax
        Lx = Ly = Lz = D_detector["pixel_size"] * qn
    s += "detector_distance = %.12e;\n" % D
    s += "detector_width = %.12e;\n" % Lx
    s += "detector_height = %.12e;\n" % Ly
    if ndim == 3:
        s += "detector_depth = %.12e;\n" % Lz
    s += "detector_pixel_width = %.12e;\n" % D_detector["pixel_size"]
    s += "detector_pixel_height = %.12e;\n" % D_detector["pixel_size"]
    if ndim == 3:
        s += "detector_pixel_depth = %.12e;\n" % D_detector["pixel_size"]
    if ndim == 2:
        s += "detector_center_x = %.12e;\n" % (D_detector["pixel_size"] *
                                               (D_detector["cx"] -
                                                (D_detector["nx"] - 1) / 2.))
        s += "detector_center_y = %.12e;\n" % (D_detector["pixel_size"] *
                                               (D_detector["cy"] -
                                                (D_detector["ny"] - 1) / 2.))
    else:
        s += "detector_center_x = 0;\n"
        s += "detector_center_y = 0;\n"
        s += "detector_center_z = 0;\n"
    s += "detector_binning = 1;\n"
    s += "experiment_wavelength = %.12e;\n" % D_source["wavelength"]
    s += "experiment_beam_intensity = %.12e;\n" % D_particle["intensity"]
    s += "experiment_polarization = \"ignore\";\n"  # polarization correction will be done in Condor if needed (see experiment.py)
    #s += "use_cuda = 0;\n"
    intrinsic_rotation = condor.utils.rotation.Rotation(
        values=D_particle["extrinsic_quaternion"], formalism="quaternion")
    intrinsic_rotation.invert()
    e0, e1, e2 = intrinsic_rotation.get_as_euler_angles("zxz")
    if not numpy.isfinite(e0):
        print "ERROR: phi is not finite"
    if not numpy.isfinite(e1):
        print "ERROR: theta is not finite"
    if not numpy.isfinite(e2):
        print "ERROR: psi is not finite"
    s += "phi = %.12e;\n" % e0
    s += "theta = %.12e;\n" % e1
    s += "psi = %.12e;\n" % e2
    s += "random_orientation = 0;\n"
    # Write string sequence to file
    tmpf_conf.writelines(s)
    # Close temporary file
    tmpf_conf_name = tmpf_conf.name
    tmpf_conf.close()
    # Read configuration into options struct
    spsim.read_options_file(tmpf_conf_name, opts)
    # This deletes the temporary files
    os.unlink(tmpf_pdb_name)
    os.unlink(tmpf_conf_name)
    return opts
Ejemplo n.º 5
0
def _conf_to_spsim_opts(D_source,D_particle,D_detector,ndim=2,qn=None,qmax=None):
    if ndim == 2:
        if qn is not None or qmax is not None:
            log_warning(logger, "As ndim=2 the passed values for qn and qmax take no effect.")
    if ndim == 3:
        if qn is None and qmax is None:
            log_and_raise_error(logger, "As ndim=3 both qn and qmax must be not None.")
            return
    import spsim
    # Create temporary file for pdb file
    tmpf_pdb = tempfile.NamedTemporaryFile(mode='w+', suffix='.conf', prefix='tmp_spsim', dir=None, delete=False)
    tmpf_pdb_name = tmpf_pdb.name
    tmpf_pdb.close()
    # Write pdb file
    mol = spsim.get_molecule_from_atoms(D_particle["atomic_numbers"], D_particle["atomic_positions"])
    spsim.write_pdb_from_mol(tmpf_pdb_name, mol)
    spsim.free_mol(mol)
    # Start with default spsim configuration
    opts = spsim.set_defaults()
    # Create temporary file for spsim configuration
    tmpf_conf = tempfile.NamedTemporaryFile(mode='w+', suffix='.conf', prefix='tmp_spsim', dir=None, delete=False)
    # Write string sequence from configuration dicts
    s = []
    s += "# THIS FILE WAS CREATED AUTOMATICALLY BY CONDOR\n"
    s += "# Temporary configuration file for spsim\n"
    s += "verbosity_level = 0;\n"
    s += "number_of_dimensions = %i;\n" % ndim
    s += "number_of_patterns = 1;\n"
    s += "origin_to_com = 1;\n"
    s += "input_type = \"pdb\";\n"
    #s += "pdb_filename = \"%s\";\n" % D_particle["pdb_filename"]
    s += "pdb_filename = \"%s\";\n" % tmpf_pdb_name
    if ndim == 2:
        D = D_detector["distance"]
        Lx = D_detector["pixel_size"] * D_detector["nx"]
        Ly = D_detector["pixel_size"] * D_detector["ny"]
    else:
        k0 = 2. * numpy.pi / D_source["wavelength"]
        D = qn / 2. * D_detector["pixel_size"] * k0 / qmax
        Lx = Ly = Lz = D_detector["pixel_size"] * qn
    s += "detector_distance = %.12e;\n" % D
    s += "detector_width = %.12e;\n" % Lx 
    s += "detector_height = %.12e;\n" % Ly
    if ndim == 3:
        s += "detector_depth = %.12e;\n" % Lz        
    s += "detector_pixel_width = %.12e;\n" % D_detector["pixel_size"]
    s += "detector_pixel_height = %.12e;\n" % D_detector["pixel_size"]
    if ndim == 3:
        s += "detector_pixel_depth = %.12e;\n" % D_detector["pixel_size"]
    if ndim == 2:
        s += "detector_center_x = %.12e;\n" % (D_detector["pixel_size"] * (D_detector["cx"] - (D_detector["nx"]-1)/2.))
        s += "detector_center_y = %.12e;\n" % (D_detector["pixel_size"] * (D_detector["cy"] - (D_detector["ny"]-1)/2.))
    else:
        s += "detector_center_x = 0;\n"
        s += "detector_center_y = 0;\n"
        s += "detector_center_z = 0;\n"
    s += "detector_binning = 1;\n"
    s += "experiment_wavelength = %.12e;\n" % D_source["wavelength"]
    s += "experiment_beam_intensity = %.12e;\n" % D_particle["intensity"]
    s += "experiment_polarization = \"ignore\";\n" # polarization correction will be done in Condor if needed (see experiment.py)
    #s += "use_cuda = 0;\n"
    intrinsic_rotation = condor.utils.rotation.Rotation(values=D_particle["extrinsic_quaternion"],formalism="quaternion")
    intrinsic_rotation.invert()
    e0, e1, e2 = intrinsic_rotation.get_as_euler_angles("zxz")
    if not numpy.isfinite(e0):
        print("ERROR: phi is not finite")
    if not numpy.isfinite(e1):
        print("ERROR: theta is not finite")
    if not numpy.isfinite(e2):
        print("ERROR: psi is not finite")
    s += "phi = %.12e;\n" % e0
    s += "theta = %.12e;\n" % e1
    s += "psi = %.12e;\n" % e2
    s += "random_orientation = 0;\n"
    # Write string sequence to file
    tmpf_conf.writelines(s)
    # Close temporary file
    tmpf_conf_name = tmpf_conf.name
    tmpf_conf.close()
    # Read configuration into options struct
    spsim.read_options_file(tmpf_conf_name, opts)
    # This deletes the temporary files
    os.unlink(tmpf_pdb_name)
    os.unlink(tmpf_conf_name)
    return opts