Return contact data from a 3D structure (in pdb format).
189291
def from_structure(structure):
    

    try:
        from Bio import PDB
        if isinstance(structure, str):
            p = PDB.PDBParser()
            structure = p.get_structure('S', structure)
        if isinstance(structure, PDB.Structure.Structure):
            for _ in structure.get_chains():
                atoms = [np.array(atom.get_coord())
                         for atom in structure.get_atoms()]
    except ImportError:
        print("Biopython not found.")
        raise

    atoms = np.array(structure)
    try:
        import scipy
        D = scipy.spatial.distance.pdist(atoms, 'euclidean')
        D = scipy.spatial.distance.squareform(D)
    except ImportError:
        print("Scipy not found.")
        raise
    m = np.max(1 / D[D != 0])
    M = np.zeros(D.shape)
    M[D != 0] = 1 / D[D != 0]
    M[D == 0] = m
    return M
1301218
def get_data(self):
        """"""
        return self.x, self.y, self.w, self.h
1002750
def shapeRecords(self):
        """"""
        return ShapeRecords([ShapeRecord(shape=rec[0], record=rec[1]) \
                                for rec in zip(self.shapes(), self.records())])
1194757
def _get_struct_linestylearray(self, shape_number):
        """"""
        obj = _make_object("LineStyleArray")
        obj.LineStyleCount = count = unpack_ui8(self._src)
        if count == 0xFF:
            obj.LineStyleCountExtended = count = unpack_ui16(self._src)
        obj.LineStyles = line_styles = []

        for _ in range(count):
            if shape_number <= 3:
                record = _make_object("LineStyle")
                record.Width = unpack_ui16(self._src)
                if shape_number <= 2:
                    record.Color = self._get_struct_rgb()
                else:
                    record.Color = self._get_struct_rgba()
            else:
                record = _make_object("LineStyle2")
                record.Width = unpack_ui16(self._src)

                bc = BitConsumer(self._src)
                record.StartCapStyle = bc.u_get(2)
                record.JoinStyle = bc.u_get(2)
                record.HasFillFlag = bc.u_get(1)
                record.NoHScaleFlag = bc.u_get(1)
                record.NoVScaleFlag = bc.u_get(1)
                record.PixelHintingFlag = bc.u_get(1)

                bc.u_get(5)  # reserved
                record.NoClose = bc.u_get(1)
                record.EndCapStyle = bc.u_get(2)

                if record.JoinStyle == 2:
                    record.MiterLimitFactor = unpack_ui16(self._src)
                if record.HasFillFlag == 0:
                    record.Color = self._get_struct_rgba()
                else:
                    record.Color = self._get_struct_fillstyle(shape_number)

            line_styles.append(record)

        return obj
825723
def tobinary(self):
        """"""
        entrylen = struct.calcsize(self.ENTRYSTRUCT)
        rslt = []
        for (dpos, dlen, ulen, flag, typcd, nm) in self.data:
            nmlen = len(nm) + 1       # add 1 for a '\0'
            # version 4
            # rslt.append(struct.pack(self.ENTRYSTRUCT+`nmlen`+'s',
            #   nmlen+entrylen, dpos, dlen, ulen, flag, typcd, nm+'\0'))
            # version 5
            #   align to 16 byte boundary so xplatform C can read
            toclen = nmlen + entrylen
            if toclen % 16 == 0:
                pad = '\0'
            else:
                padlen = 16 - (toclen % 16)
                pad = '\0'*padlen
                nmlen = nmlen + padlen
            rslt.append(struct.pack(self.ENTRYSTRUCT+`nmlen`+'s',
                            nmlen+entrylen, dpos, dlen, ulen, flag, typcd, nm+pad))
            # end version 5

        return ''.join(rslt)
258392
def get_message(self):
        """"""

        result = ''
        if self._data_struct is not None:
            result = self._data_struct[KEY_MESSAGE]
        return result
1090002
def load(self, d3mds):
        """"""
        X, y = d3mds.get_data()

        return Dataset(d3mds.dataset_id, X, y)
1369910
def _get_struct_matrix(self):
        """"""
        obj = _make_object("Matrix")
        bc = BitConsumer(self._src)

        # scale
        obj.HasScale = bc.u_get(1)
        if obj.HasScale:
            obj.NScaleBits = n_scale_bits = bc.u_get(5)
            obj.ScaleX = bc.fb_get(n_scale_bits)
            obj.ScaleY = bc.fb_get(n_scale_bits)

        # rotate
        obj.HasRotate = bc.u_get(1)
        if obj.HasRotate:
            obj.NRotateBits = n_rotate_bits = bc.u_get(5)
            obj.RotateSkew0 = bc.fb_get(n_rotate_bits)
            obj.RotateSkew1 = bc.fb_get(n_rotate_bits)

        # translate
        obj.NTranslateBits = n_translate_bits = bc.u_get(5)
        obj.TranslateX = bc.s_get(n_translate_bits)
        obj.TranslateY = bc.s_get(n_translate_bits)
        if not self._read_twips:
            obj.TranslateX /= 20.0
            obj.TranslateY /= 20.0
        return obj
1077140
def object_to_items(data_structure):
    """"""
    items = []
    # Get all items from dict
    try:
        items = list(data_structure.__dict__.items())
    except:
        pass
    # Get all slots
    hierarchy = [data_structure]
    try:
        hierarchy += inspect.getmro(data_structure)
    except:
        pass
    slots = []
    try:
        for b in hierarchy:
            try:
                slots += b.__slots__
            except:  # pragma: no cover
                pass
    except:  # pragma: no cover
        pass
    # Get attrs from slots
    for x in slots:
        items.append((x, getattr(data_structure, x)))
    return items
528891
def as_dict(self, depth=0):
        
        result_dict = {}
        for column in self.__table__.columns.keys():
            result_dict[column] = getattr(self, column, None)
            if isinstance(result_dict[column], Decimal):
                result_dict[column] = str(result_dict[column])
        result_dict['links'] = self.links()
        for foreign_key in self.__table__.foreign_keys:
            column_name = foreign_key.column.name
            column_value = getattr(self, column_name, None)
            if column_value:
                table = foreign_key.column.table.name
                with app.app_context():
                    endpoint = current_app.class_references[table]
                    session = db.session()
                    resource = session.query(endpoint).get(column_value)
                if depth > 0:
                    result_dict.update({
                        'rel': endpoint.__name__,
                        endpoint.__name__.lower(): resource.as_dict(depth - 1)
                        })
                else:
                    result_dict[
                        endpoint.__name__.lower() + '_url'] = '/{}/{}'.format(
                        endpoint.__name__, column_value)

        result_dict['self'] = self.resource_uri()
        return result_dict
1096690
def shape(self):
        """"""
        if not self.data:
            return (0, 0)
        return (len(self.data), len(self.dimensions))
630128
def extract_db_info(self, obj, keys):
        """"""

        objl = self.convert(obj)

        result = super(DataFrameType, self).extract_db_info(objl, keys)
        ext = self.datamodel.extractor_map['fits']
        if objl:
            with objl.open() as hdulist:
                for field in keys:
                    result[field] = ext.extract(field, hdulist)

                tags = result['tags']
                for field in self.tags_keys:
                    tags[field] = ext.extract(field, hdulist)

                return result
        else:
            return result
544585
def to_array(self):
        
        array = super(InlineQueryResultContact, self).to_array()
        # 'type' and 'id' given by superclass
        array['phone_number'] = u(self.phone_number)  # py2: type unicode, py3: type str
        array['first_name'] = u(self.first_name)  # py2: type unicode, py3: type str
        if self.last_name is not None:
            array['last_name'] = u(self.last_name)  # py2: type unicode, py3: type str
        if self.reply_markup is not None:
            array['reply_markup'] = self.reply_markup.to_array()  # type InlineKeyboardMarkup
        if self.input_message_content is not None:
            array['input_message_content'] = self.input_message_content.to_array()  # type InputMessageContent
        if self.thumb_url is not None:
            array['thumb_url'] = u(self.thumb_url)  # py2: type unicode, py3: type str
        if self.thumb_width is not None:
            array['thumb_width'] = int(self.thumb_width)  # type int
        if self.thumb_height is not None:
            array['thumb_height'] = int(self.thumb_height)  # type int
        return array
1022556
private static List<ContactDetails> fetchDataList() {
		List<ContactDetails> list = new ArrayList<>();
		list.add(new ContactDetails("David", "1234", new String[]{"a", "b"}));
		list.add(new ContactDetails("Jun", "1111", new String[]{"c"}));
		list.add(new ContactDetails("Martin", null, new String[]{"b"}));
		return list;
	}
267140
def _get_struct_fillstylearray(self, shape_number):
        """"""
        obj = _make_object("FillStyleArray")
        obj.FillStyleCount = count = unpack_ui8(self._src)
        if count == 0xFF:
            obj.FillStyleCountExtended = count = unpack_ui16(self._src)
        obj.FillStyles = [self._get_struct_fillstyle(shape_number)
                          for _ in range(count)]
        return obj
491541
def get_contact(self, jid):
        
        try:
            return self.get_contacts()[jid.bare()]
        except KeyError:
            raise ContactNotFound
        except AttributeError:
            raise AttributeError("jid must be an aioxmpp.JID object")
399211
def M(self):
        
        N = self.N
        tig_to_idx = self.tig_to_idx
        M = np.zeros((N, N), dtype=int)
        for (at, bt), links in self.contacts.items():
            if not (at in tig_to_idx and bt in tig_to_idx):
                continue
            ai = tig_to_idx[at]
            bi = tig_to_idx[bt]
            M[ai, bi] = M[bi, ai] = links
        return M