Exemple #1
0
def fetch_emdb_map(id, directory, tmpDirectory):
    """ get map from emd
    :param id: 3D MAP ID in EMDB
    :return: local 3Dmap filename
    """
    import socket

    # get computer name and select server
    url_rest_api = "https://www.ebi.ac.uk/pdbe/api/emdb/entry/map/EMD-%d"
    hname = socket.gethostname()
    if hname.endswith('.edu') or hname.endswith('.gov'):
        site = 'ftp.wwpdb.org'
        url_pattern = 'ftp://%s/pub/emdb/structures/EMD-%s/map/%s'
    elif hname.endswith('.cn'):
        site = 'ftp.emdb-china.org'
        url_pattern = 'ftp://%s/structures/EMD-%s/map/%s'
    else:
        site = 'ftp.ebi.ac.uk'
        url_pattern = 'ftp://%s/pub/databases/emdb/structures/EMD-%s/map/%s'

    map_name = 'emd_%s.map' % id
    map_gz_name = map_name + '.gz'
    map_url = url_pattern % (site, id, map_gz_name)
    name = 'EMD-%d' % id
    minimum_map_size = 8192  # bytes
    url_rest_api = url_rest_api % id

    try:
        map_path, samplingAPI, originAPI = fetch_file(map_url, url_rest_api,
                                                      name, minimum_map_size,
                                                      directory, tmpDirectory,
                                                      map_name)
    except Exception as e:
        raise Exception("Cannot retrieve File from EMDB", e)

    originAPI = array(originAPI) * samplingAPI  # convert to Angstrom
    #check consistency between file header and rest API
    ccp4header = emconv.Ccp4Header(map_path, readHeader=True)
    samplingHeader = ccp4header.computeSampling()  # unit = A/px
    originHeader = array(ccp4header.getOrigin())  # unit = A

    if abs(samplingHeader - samplingAPI) >= 0.01:
        print("###########################\n"
              "WARNING: sampling rate stored in EMDB\n"
              "database and 3D map header file do not match\n"
              "API=%f, header=%f\n"
              "###########################\n" % (samplingAPI, samplingHeader))

    if norm(originHeader - originAPI) >= 0.1:
        print("###########################\n"
              "WARNING: origin  stored in EMDB\n"
              "database and 3D map header file do not match\n"
              "API=%f, header=%f\n"
              "###########################\n" % (originAPI, originHeader))
    return map_path, samplingAPI, originAPI
Exemple #2
0
    def show(self, form, *params):
        protocol = form.protocol
        vol = protocol.inVolume.get()
        fullPattern = vol.getFileName()
        sampling = vol.getSamplingRate()
        if ((str(fullPattern)).endswith('mrc')
                or (str(fullPattern)).endswith('map')):
            ccp4header = emconv.Ccp4Header(fullPattern, readHeader=True)
            x, y, z = ccp4header.getOrigin(changeSign=True)  # In Angstroms
        else:
            x, y, z = \
                ImportOriginVolumeWizard._halfOriginCoordinates(vol, sampling)

        form.setVar('x', round(x, 3))
        form.setVar('y', round(y, 3))
        form.setVar('z', round(z, 3))
        form.setVar('samplingRate', round(sampling, 3))
Exemple #3
0
    def show(self, form, *params):
        protocol = form.protocol
        vol = protocol.inVolume.get()
        fullPattern = vol.getLocation()
        sampling = vol.getSamplingRate()
        if ((str(fullPattern)).endswith('mrc')
                or (str(fullPattern)).endswith('map')):
            ccp4header = emconv.Ccp4Header(fullPattern, readHeader=True)
            x, y, z = ccp4header.getOrigin(changeSign=True)  # In Angstroms
        else:
            x, y, z = \
                ImportOriginVolumeWizard._halfOriginCoordinates(vol, sampling)

        def remove_tail_zeros(number):
            return decimal.Decimal(number).normalize()

        form.setVar('x', remove_tail_zeros(x))
        form.setVar('y', remove_tail_zeros(y))
        form.setVar('z', remove_tail_zeros(z))
        form.setVar('samplingRate', remove_tail_zeros(sampling))
Exemple #4
0
    def show(self, form, *params):
        protocol = form.protocol
        filesPath = protocol.filesPath.get()
        filesPattern = protocol.filesPattern.get()
        if filesPattern:
            fullPattern = os.path.join(filesPath, filesPattern)
        else:
            fullPattern = filesPath

        sampling = protocol.samplingRate.get()
        for fileName, fileId in protocol.iterFiles():
            inputVol = emobj.Volume()
            inputVol.setFileName(fileName)
            if ((str(fullPattern)).endswith('mrc')
                    or (str(fullPattern)).endswith('map')):
                ccp4header = emconv.Ccp4Header(fileName, readHeader=True)
                x, y, z = ccp4header.getOrigin(changeSign=True)  # In Angstroms
            else:
                x, y, z = self._halfOriginCoordinates(inputVol, sampling)

            form.setVar('x', x)
            form.setVar('y', y)
            form.setVar('z', z)
Exemple #5
0
def fetch_emdb_map(id, directory, tmpDirectory):
    """ get map from emd
    :param id: 3D MAP ID in EMDB
    :return: local 3Dmap filename
    """
    import socket

    # get computer name and select server
    url_rest_api = "https://www.ebi.ac.uk/pdbe/api/emdb/entry/map/EMD-%d"
    hname = socket.gethostname()
    if hname.endswith('.edu') or hname.endswith('.gov'):
        site = 'ftp.wwpdb.org'
        url_pattern = 'ftp://%s/pub/emdb/structures/EMD-%s/map/%s'
    elif hname.endswith('.cn'):
        site = 'ftp.emdb-china.org'
        url_pattern = 'ftp://%s/structures/EMD-%s/map/%s'
    else:
        site = 'ftp.ebi.ac.uk'
        url_pattern = 'ftp://%s/pub/databases/emdb/structures/EMD-%s/map/%s'

    map_name = 'emd_%s.map' % id
    map_gz_name = map_name + '.gz'
    map_url = url_pattern % (site, id, map_gz_name)
    name = 'EMD-%d' % id
    minimum_map_size = 8192  # bytes
    url_rest_api = url_rest_api % id

    nTimes = 3
    for i in range(nTimes):  # if error repeat the fetch file up to nTimes
        try:
            # raise Exception("test")  # uncomment to test this loop
            map_path, samplingAPI, originAPI = fetch_file(
                map_url, url_rest_api, name, minimum_map_size, directory,
                tmpDirectory, map_name)
            break
        except Exception as e:
            print("Retieving 3D map with id=", id,
                  "failed retrying (%d/%d)" % (i + 1, nTimes))
            print("Error:", e)
    # Loop statements may have an else clause; it is executed
    # when the loop terminates through exhaustion of the iterable
    else:
        raise Exception("Cannot retrieve File from EMDB")

    originAPI = array(originAPI) * samplingAPI  # convert to Angstrom
    # check consistency between file header and rest API
    ccp4header = emconv.Ccp4Header(map_path, readHeader=True)
    samplingHeader = ccp4header.computeSampling()  # unit = A/px
    originHeader = array(ccp4header.getOrigin())  # unit = A

    if abs(samplingHeader - samplingAPI) >= 0.01:
        print("###########################\n"
              "WARNING: sampling rate stored in EMDB\n"
              "database and 3D map header file do not match\n"
              "API=%f, header=%f\n"
              "###########################\n" % (samplingAPI, samplingHeader))

    if norm(originHeader - originAPI) >= 0.1:
        print("###########################\n"
              "WARNING: origin  stored in EMDB\n"
              "database and 3D map header file do not match\n"
              "API=%f, header=%f\n"
              "###########################\n" % (originAPI, originHeader))
    return map_path, samplingAPI, originAPI