コード例 #1
0
def delete_data(file_id, collection_id=None):

    if in_orion():

        if collection_id is None:
            raise ValueError("The Collection ID is None")

        # session = APISession

        session = OrionSession(requests_session=get_session(
            retry_dict={
                403: 5,
                404: 20,
                409: 45,
                460: 15,
                500: 2,
                502: 45,
                503: 45,
                504: 45,
            }))

        collection = session.get_resource(ShardCollection, collection_id)

        session.delete_resource(Shard(collection=collection, id=file_id))

    else:
        os.remove(file_id)

    return True
コード例 #2
0
def upload_data(filename, collection_id=None, shard_name=""):

    if in_orion():

        if collection_id is None:
            raise ValueError("The Collection ID is None")

        # session = APISession

        session = OrionSession(requests_session=get_session(
            retry_dict={
                403: 5,
                404: 20,
                409: 45,
                460: 15,
                500: 2,
                502: 45,
                503: 45,
                504: 45,
            }))

        collection = session.get_resource(ShardCollection, collection_id)

        shard = try_hard_to_create_shard(collection, filename, name=shard_name)

        file_id = shard.id

        shard.close()

    else:
        file_id = filename

    return file_id
コード例 #3
0
def delete_file(file_id):

    if in_orion():

        # session = APISession

        session = OrionSession(requests_session=get_session(
            retry_dict={
                403: 5,
                404: 20,
                409: 45,
                460: 15,
                500: 2,
                502: 45,
                503: 45,
                504: 45,
            }))

        resource = session.get_resource(File, file_id)

        session.delete_resource(resource)

    else:
        os.remove(file_id)

    return True
コード例 #4
0
def download_file(file_id, filename):

    if in_orion():

        # session = APISession

        session = OrionSession(requests_session=get_session(
            retry_dict={
                403: 5,
                404: 20,
                409: 45,
                460: 15,
                500: 2,
                502: 45,
                503: 45,
                504: 45,
            }))

        resource = session.get_resource(File, file_id)

        resource.download_to_file(filename)

        fn_local = filename

    else:
        fn_local = file_id

    if not os.path.isfile(fn_local):
        raise IOError(
            "The trajectory file has not been found: {}".format(fn_local))

    return fn_local
コード例 #5
0
def upload_file(filename, orion_ui_name='OrionFile'):

    if in_orion():

        # session = APISession

        session = OrionSession(requests_session=get_session(
            retry_dict={
                403: 5,
                404: 20,
                409: 45,
                460: 15,
                500: 2,
                502: 45,
                503: 45,
                504: 45,
            }))

        file_upload = File.upload(session, orion_ui_name, filename)

        session.tag_resource(file_upload, "Trajectory")

        job_id = environ.get('ORION_JOB_ID')

        if job_id:
            session.tag_resource(file_upload, "Job {}".format(job_id))

        file_id = file_upload.id

    else:
        file_id = filename

    return file_id
コード例 #6
0
    def get_protein_traj(self):
        """
        This method returns the protein molecule where conformers have been set as trajectory frames

        Parameters
        ----------
        Returns
        -------
        multi_conformer_protein: OEMol
            The multi conformer protein
        """

        if not self.rec.has_field(Fields.protein_traj_confs):
            raise ValueError(
                "The protein conformer trajectory is not present on the record"
            )

        protein_conf = self.rec.get_value(Fields.protein_traj_confs)

        if in_orion():

            # session = APISession

            session = OrionSession(requests_session=get_session(
                retry_dict={
                    403: 5,
                    404: 20,
                    409: 45,
                    460: 15,
                    500: 2,
                    502: 45,
                    503: 45,
                    504: 45,
                }))

            if self.collection_id is None:
                raise ValueError("The Collection ID is None")

            collection = session.get_resource(ShardCollection,
                                              self.collection_id)

            shard = session.get_resource(Shard(collection=collection),
                                         protein_conf)

            with TemporaryDirectory() as output_directory:

                protein_fn = os.path.join(output_directory,
                                          MDFileNames.trajectory_conformers)

                try_hard_to_download_shard(shard, protein_fn)

                protein_conf = oechem.OEMol()

                with oechem.oemolistream(protein_fn) as ifs:
                    oechem.OEReadMolecule(ifs, protein_conf)

            shard.close()

        return protein_conf
コード例 #7
0
ファイル: command_line.py プロジェクト: oess/openmm_orion
def main(ctx, profile):
    ctx.obj = dict()
    ctx.obj['session'] = orionclient.session.OrionSession(
        orionclient.session.get_profile_config(profile=profile),
        requests_session=get_session(retry_dict={
            403: 5,
            404: 20,
            409: 45,
            460: 15,
            500: 2,
            502: 45,
            503: 45,
            504: 45,
        }))
コード例 #8
0
    def create_collection(self, name):
        """
        This method sets a collection field on the record to be used in Orion

        Parameters
        -----------
        name: String
            A string used to identify in the Orion UI the collection

        Returns
        -------
        boolean : Bool
                True if the collection creation in Orion was successful otherwise False
        """

        if in_orion():

            if self.rec.has_field(Fields.collection):
                raise ValueError(
                    "Collection field already present on the record")

            # session = APISession

            session = OrionSession(requests_session=get_session(
                retry_dict={
                    403: 5,
                    404: 20,
                    409: 45,
                    460: 15,
                    500: 2,
                    502: 45,
                    503: 45,
                    504: 45,
                }))

            collection = ShardCollection.create(session, name)

            self.rec.set_value(Fields.collection, collection.id)

            self.collection_id = collection.id

        else:
            return False

        return True
コード例 #9
0
    def delete_parmed(self):
        """
        This method deletes the Parmed object from the record. True is returned if the deletion was
        successful.

        Parameters
        ----------

        Returns
        -------
        boolean : Bool
            True if Parmed object deletion was successful
        """

        if not self.has_parmed:
            raise ValueError(
                "The Parmed structure is not present on the record")

        if in_orion():

            if self.collection_id is None:
                raise ValueError("The Collection ID is None")

            session = OrionSession(requests_session=get_session(
                retry_dict={
                    403: 5,
                    404: 20,
                    409: 45,
                    460: 15,
                    500: 2,
                    502: 45,
                    503: 45,
                    504: 45,
                }))

            collection = session.get_resource(ShardCollection,
                                              self.collection_id)

            file_id = self.rec.get_value(Fields.pmd_structure)

            session.delete_resource(Shard(collection=collection, id=file_id))

        self.rec.delete_field(Fields.pmd_structure)

        return True
コード例 #10
0
def download_data(file_id, path, collection_id=None):

    if in_orion():

        if collection_id is None:
            raise ValueError("The Collection ID is None")

        # session = APISession

        session = OrionSession(requests_session=get_session(
            retry_dict={
                403: 5,
                404: 20,
                409: 45,
                460: 15,
                500: 2,
                502: 45,
                503: 45,
                504: 45,
            }))

        collection = session.get_resource(ShardCollection, collection_id)

        shard = session.get_resource(Shard(collection=collection), file_id)

        from MDOrion.Standards import MDFileNames

        fn_local = os.path.join(path, MDFileNames.mddata)

        try_hard_to_download_shard(shard, fn_local)

        shard.close()

    else:
        fn_local = file_id

    if not os.path.isfile(fn_local):
        raise IOError(
            "The MD data file has not been found: {}".format(fn_local))

    return fn_local
コード例 #11
0
    def set_protein_traj(self, protein_conf, shard_name=""):
        """
        This method sets the multi conformer protein trajectory on the record

        Parameters
        -----------
        protein_conf: OEChem
            Th multi conformer protein trajectory
        shard_name: String
            In Orion tha shard will be named by using the shard_name

        Returns
        -------
        boolean: Bool
            True if the setting was successful
        """

        if not isinstance(protein_conf, oechem.OEMol):
            raise ValueError(
                "The passed Parmed object is not a valid Parmed Structure: {}".
                format(type(protein_conf)))

        if in_orion():

            with TemporaryDirectory() as output_directory:

                protein_fn = os.path.join(output_directory,
                                          MDFileNames.trajectory_conformers)

                with oechem.oemolostream(protein_fn) as ofs:
                    oechem.OEWriteConstMolecule(ofs, protein_conf)

                if self.collection_id is None:
                    raise ValueError("The Collection ID is None")

                if self.rec.has_field(Fields.protein_traj_confs):
                    fid = self.rec.get_value(Fields.protein_traj_confs)
                    utils.delete_data(fid, collection_id=self.collection_id)

                # session = APISession

                session = OrionSession(requests_session=get_session(
                    retry_dict={
                        403: 5,
                        404: 20,
                        409: 45,
                        460: 15,
                        500: 2,
                        502: 45,
                        503: 45,
                        504: 45,
                    }))

                collection = session.get_resource(ShardCollection,
                                                  self.collection_id)

                shard = try_hard_to_create_shard(collection,
                                                 protein_fn,
                                                 name=shard_name)

                shard.close()

                self.rec.set_value(Fields.protein_traj_confs, shard.id)
        else:
            self.rec.set_value(Fields.protein_traj_confs, protein_conf)

        return True
コード例 #12
0
    def set_parmed(self, pmd, sync_stage_name=None, shard_name=""):
        """
        This method sets the Parmed object. Return True if the setting was successful.
        If sync_stage_name is not None the parmed structure positions, velocities and
        box vectors will be synchronized with the MD State selected by passing the MD
        stage name

        Parameters
        ----------
        pmd: Parmed Structure object
            The Parmed Structure object to be set on the record
        sync_stage_name: String or None
            The stage name that is used to synchronize the Parmed structure
        shard_name: String
            In Orion tha shard will be named by using the shard_name

        Returns
        -------
        boolean : Bool
            True if the setting was successful
        """

        if not isinstance(pmd, parmed.Structure):
            raise ValueError(
                "The passed Parmed object is not a valid Parmed Structure: {}".
                format(type(pmd)))

        if sync_stage_name is not None:

            mdstate = self.get_stage_state(stg_name=sync_stage_name)

            pmd.positions = mdstate.get_positions()
            pmd.velocities = mdstate.get_velocities()
            pmd.box_vectors = mdstate.get_box_vectors()

        if in_orion():

            with TemporaryDirectory() as output_directory:

                parmed_fn = os.path.join(output_directory, 'parmed.pickle')

                with open(parmed_fn, 'wb') as f:
                    pickle.dump(pmd.__getstate__(), f)

                if self.collection_id is None:
                    raise ValueError("The Collection ID is None")

                if self.rec.has_field(Fields.pmd_structure):
                    fid = self.rec.get_value(Fields.pmd_structure)
                    utils.delete_data(fid, collection_id=self.collection_id)

                session = OrionSession(requests_session=get_session(
                    retry_dict={
                        403: 5,
                        404: 20,
                        409: 45,
                        460: 15,
                        500: 2,
                        502: 45,
                        503: 45,
                        504: 45,
                    }))

                collection = session.get_resource(ShardCollection,
                                                  self.collection_id)

                shard = try_hard_to_create_shard(collection,
                                                 parmed_fn,
                                                 name=shard_name)

                shard.close()

                self.rec.set_value(Fields.pmd_structure, shard.id)
        else:
            self.rec.set_value(Fields.pmd_structure, pmd)

        return True
コード例 #13
0
    def get_parmed(self, sync_stage_name=None):
        """
        This method returns the Parmed object. An exception is raised if the Parmed object cannot
        be found. If sync_stage_name is not None the parmed structure positions, velocities and
        box vectors will be synchronized with the MD State selected by passing the MD stage name

        Parameters
        ----------
        sync_stage_name: String or None
            The stage name that is used to synchronize the Parmed structure

        Returns
        -------
        parmed : Parmed Structure
            The Parmed Structure object
        """

        if not self.rec.has_field(Fields.pmd_structure):
            raise ValueError(
                "The Parmed reference is not present on the record")

        pmd_structure = self.rec.get_value(Fields.pmd_structure)

        if in_orion():
            # session = APISession

            session = OrionSession(requests_session=get_session(
                retry_dict={
                    403: 5,
                    404: 20,
                    409: 45,
                    460: 15,
                    500: 2,
                    502: 45,
                    503: 45,
                    504: 45,
                }))

            if self.collection_id is None:
                raise ValueError("The Collection ID is None")

            collection = session.get_resource(ShardCollection,
                                              self.collection_id)

            shard = session.get_resource(Shard(collection=collection),
                                         pmd_structure)

            with TemporaryDirectory() as output_directory:

                parmed_fn = os.path.join(output_directory, "parmed.pickle")

                try_hard_to_download_shard(shard, parmed_fn)

                with open(parmed_fn, 'rb') as f:
                    parm_dic = pickle.load(f)

                pmd_structure = parmed.structure.Structure()
                pmd_structure.__setstate__(parm_dic)

            shard.close()

        if sync_stage_name is not None:
            mdstate = self.get_stage_state(stg_name=sync_stage_name)

            pmd_structure.positions = mdstate.get_positions()
            pmd_structure.velocities = mdstate.get_velocities()
            pmd_structure.box_vectors = mdstate.get_box_vectors()

        return pmd_structure