Example #1
0
 def sample(self, val):
     """ Set the 'sample' parameter to val."""
     if val is None:
         raise ValueError( "A sample must be defined.")
     if val.split(".")[-1] == "pdb":
         print("Checking presence of %s. Will query from PDB if not found in $PWD." % (val))
         self.__sample = IOUtilities.checkAndGetPDB(val)
         print("Sample path is set to %s." % (self.__sample))
Example #2
0
 def sample(self, val):
     """ Set the 'sample' parameter to val."""
     if val is None:
         self.__sample = None
         return
     if val.split(".")[-1] == "pdb":
         self.__sample = IOUtilities.checkAndGetPDB(val)
         return
     raise IOError("Samples must be in pdb format.")
Example #3
0
    def testQueryPDBTwice(self):
        """ Check that we can do two subsequent queries (fails if urllib.urlcleanup is not called.) """
        # Setup path to pdb file.
        pdb_path = '5loy.pdb'
        self.__files_to_remove.append(pdb_path)
        self.__paths_to_remove.append('obsolete')

        # Attempt to load it.
        pdb_path = IOUtilities.checkAndGetPDB(pdb_path)

        # Check it's there.
        self.assertTrue( os.path.isfile( pdb_path ) )

        # Remove it.
        os.remove(pdb_path)

        # Query again.
        pdb_path = IOUtilities.checkAndGetPDB(pdb_path)

        # Check it's there.
        self.assertTrue( os.path.isfile( pdb_path ) )
Example #4
0
    def testQueryPDB(self):
        """ Check that we can query a non-existing pdb from pdb.org and convert it to a dict. """
        # Setup path to pdb file.
        pdb_path = '5UDC.pdb'
        self.__files_to_remove.append(pdb_path)
        self.__paths_to_remove.append('obsolete')

        # Attempt to load it.
        pdb_path = IOUtilities.checkAndGetPDB(pdb_path)

        # Check it's there.
        self.assertTrue( os.path.isfile( pdb_path ) )
Example #5
0
 def sample(self, val):
     """ Set the 'sample' parameter to val."""
     if val is None:
         raise ValueError( "A sample must be defined.")
     if val.split(".")[-1] == "pdb":
         self.__sample = IOUtilities.checkAndGetPDB(val)
Example #6
0
    def backengine(self):
        """ This method drives the backengine singFEL."""

        uniform_rotation = self.parameters.uniform_rotation
        calculate_Compton = int(self.parameters.calculate_Compton)
        slice_interval = self.parameters.slice_interval
        number_of_slices = self.parameters.number_of_slices
        pmi_start_ID = self.parameters.pmi_start_ID
        pmi_stop_ID = self.parameters.pmi_stop_ID
        number_of_diffraction_patterns = self.parameters.number_of_diffraction_patterns

        if not os.path.isdir(self.output_path):
            os.mkdir(self.output_path)
        self.__output_dir = self.output_path

        # If the sample is passed as a pdb, branch out to separate backengine implementation.
        if self.input_path.split(".")[-1].lower() == 'pdb':
            if not os.path.isfile(self.input_path):
                # Attempt to query from pdb.
                self.input_path = IOUtilities.checkAndGetPDB(self.input_path)

            return self._backengineWithPdb()

        # Ok, not a pdb, proceed.
        # Serialize the geometry file.
        beam_geometry_file = "tmp.geom"
        self.parameters.detector_geometry.serialize(beam_geometry_file)

        # Setup directory to pmi output.
        # Backengine expects a directory name, so have to check if
        # input_path is dir or file and handle accordingly.
        if os.path.isdir(self.input_path):
            input_dir = self.input_path

        elif os.path.isfile(self.input_path):
            input_dir = os.path.dirname(self.input_path)

        config_file = '/dev/null'

        # collect MPI arguments
        if self.parameters.forced_mpi_command == "":
            np, ncores = self.computeNTasks()
            mpicommand = ParallelUtilities.prepareMPICommandArguments(np,1)
        else:
            mpicommand = self.parameters.forced_mpi_command


# collect program arguments
        command_sequence = ['radiationDamageMPI',
                            '--inputDir',         str(input_dir),
                            '--outputDir',        str(self.__output_dir),
                            '--geomFile',         str(beam_geometry_file),
                            '--configFile',       str(config_file),
                            '--uniformRotation',  str(uniform_rotation),
                            '--calculateCompton', str(calculate_Compton),
                            '--sliceInterval',    str(slice_interval),
                            '--numSlices',        str(number_of_slices),
                            '--pmiStartID',       str(pmi_start_ID),
                            '--pmiEndID',         str(pmi_stop_ID),
                            '--numDP',            str(number_of_diffraction_patterns),
                            ]

        if self.parameters.beam_parameters is not None:
            beam_parameter_file = "tmp.beam"
            self.parameters.beam_parameters.serialize(beam_parameter_file)

            command_sequence.append('--beamFile')
            command_sequence.append(str(beam_parameter_file))

        # put MPI and program arguments together
        args = shlex.split(mpicommand) + command_sequence

        if 'SIMEX_VERBOSE' in os.environ:
            print(("SingFELPhotonDiffractor backengine command: "
                   + " ".join(args)),flush=True)

        # Run the backengine command.
        proc = subprocess.Popen(args)
        proc.wait()

        # Return the return code from the backengine.
        return proc.returncode