Return primaty (top, bridge, hollow, 4fold) and
        secondary (chemical elements in close environment) site designation
350010
def get_site(self, plot_voronoi_sites=False):
        """"""

        if self.dissociated:
            return 'dissociated', ''

        if self.is_desorbed():
            return 'desorbed', ''

        if self.is_subsurface():
            return 'subsurface', ''

        C0 = self.B[-1:] * (3, 3, 1)
        ads_pos = C0.positions[4]

        C = self.B.copy() * (3, 3, 1)

        # Use top layer and adsorbate to map sites
        Dict = self.get_site_dict(ads_pos[:2])

        primary_site = None
        dis = self.B.get_cell()[0][0]
        Kind = None

        values = [np.linalg.norm(ads_pos[:2] - d['pos'][:2])
                  for d in list(Dict.values())]
        if len(values) == 0:
            return 'N/A', ''
        idx = np.argmin(values)
        dis = values[idx]
        kind = list(Dict.keys())[idx]
        primary_site = kind.split('_')[0]

        if plot_voronoi_sites:  # View sampled sites
            X = self.B.copy()
            X = X * (3, 3, 1)
            del X[-1]
            for pos in Dict.values():
                add_adsorbate(X, 'X', position=(pos['pos'][:2]), height=0.2)
            view(X)

        if primary_site == 'top':
            site_type = Dict[kind]['sym']

        if primary_site == 'bridge':
            site_type = Dict[kind]['sym'] + '|' + self.get_under_bridge()

        elif primary_site == 'hollow':
            site_type = Dict[kind]['sym'] + '|' + self.get_under_hollow()

        elif primary_site == '4fold':
            site_type = Dict[kind]['sym']

        if dis > 0.5:
            primary_site += '-tilt'
            print('Warning: A strong site match could not be found!')
            print('  structure labeled as {}'.format(primary_site))

        return primary_site, site_type
390869
def to_primitive(self, context=None):
        
        return {
            'name': self.name,
            'items': [x.to_primitive(context) for x in self.iterconstants()]
        }
1243087
def _get_shallow_site_response_term(self, C, vs30, pga_rock):
        
        vs_mod = vs30 / C["k1"]
        # Get linear global site response term
        f_site_g = C["c11"] * np.log(vs_mod)
        idx = vs30 > C["k1"]
        f_site_g[idx] = f_site_g[idx] + (C["k2"] * self.CONSTS["n"] *
                                         np.log(vs_mod[idx]))

        # Get nonlinear site response term
        idx = np.logical_not(idx)
        if np.any(idx):
            f_site_g[idx] = f_site_g[idx] + C["k2"] * (
                np.log(pga_rock[idx] +
                       self.CONSTS["c"] * (vs_mod[idx] ** self.CONSTS["n"])) -
                np.log(pga_rock[idx] + self.CONSTS["c"])
                )

        # For Japan sites (SJ = 1) further scaling is needed (equation 19)
        if self.CONSTS["SJ"]:
            fsite_j = np.log(vs_mod)
            idx = vs30 > 200.0
            if np.any(idx):
                fsite_j[idx] = (C["c13"] + C["k2"] * self.CONSTS["n"]) *\
                    fsite_j[idx]
            idx = np.logical_not(idx)
            if np.any(idx):
                fsite_j[idx] = (C["c12"] + C["k2"] * self.CONSTS["n"]) *\
                    (fsite_j[idx] - np.log(200.0 / C["k1"]))

            return f_site_g + fsite_j
        else:
            return f_site_g
211639
function getRelatives(slideePos) {
            slideePos = within(isNumber(slideePos) ? slideePos : pos.dest, pos.start, pos.end);

            var relatives = {},
                centerOffset = forceCenteredNav ? 0 : frameSize / 2;

            // Determine active page
            if (!parallax) {
                for (var p = 0, pl = pages.length; p < pl; p++) {
                    if (slideePos >= pos.end || p === pages.length - 1) {
                        relatives.activePage = pages.length - 1;
                        break;
                    }

                    if (slideePos <= pages[p] + centerOffset) {
                        relatives.activePage = p;
                        break;
                    }
                }
            }

            // Relative item indexes
            if (itemNav) {
                var first = false,
                    last = false,
                    center = false;

                // From start
                for (var i = 0, il = items.length; i < il; i++) {
                    // First item
                    if (first === false && slideePos <= items[i].start) {
                        first = i;
                    }

                    // Centered item
                    if (center === false && slideePos - items[i].size / 2 <= items[i].center) {
                        center = i;
                    }

                    // Last item
                    if (i === items.length - 1 || (last === false && slideePos < items[i + 1].end)) {
                        last = i;
                    }

                    // Terminate if all are assigned
                    if (last !== false) {
                        break;
                    }
                }

                // Safe assignment, just to be sure the false won't be returned
                relatives.firstItem  = isNumber(first) ? first : 0;
                relatives.centerItem = isNumber(center) ? center : relatives.firstItem;
                relatives.lastItem   = isNumber(last) ? last : relatives.centerItem;
            }

            return relatives;
        }
632481
def get_stack(self, xvals, yvals, baselines, sign='positive'):
        
        bottoms, tops = [], []
        for x, y in zip(xvals, yvals):
            baseline = baselines[x][sign]
            if sign == 'positive':
                bottom = baseline
                top = bottom+y
                baseline = top
            else:
                top = baseline
                bottom = top+y
                baseline = bottom
            baselines[x][sign] = baseline
            bottoms.append(bottom)
            tops.append(top)
        return bottoms, tops
604302
def _elements(self):
        """"""
        ElementCls, element_dicts = self._element_makings
        return tuple(
            ElementCls(element_dict, idx, element_dicts)
            for idx, element_dict in enumerate(element_dicts)
        )
370034
def get_primary(self):
        """"""
        # Implemented here in Topology instead of MongoClient, so it can lock.
        with self._lock:
            topology_type = self._description.topology_type
            if topology_type != TOPOLOGY_TYPE.ReplicaSetWithPrimary:
                return None

            return writable_server_selector(self._new_selection())[0].address
211374
def composition(self):
        
        elmap = collections.defaultdict(float)
        for site in self:
            for species, occu in site.species.items():
                elmap[species] += occu
        return Composition(elmap)
650916
long lastCEWithPrimaryBefore(long p) {
        if(p == 0) { return 0; }
        assert(p > elements[(int)elements[IX_FIRST_PRIMARY_INDEX]]);
        int index = findP(p);
        long q = elements[index];
        long secTer;
        if(p == (q & 0xffffff00L)) {
            // p == elements[index] is a root primary. Find the CE before it.
            // We must not be in a primary range.
            assert((q & PRIMARY_STEP_MASK) == 0);
            secTer = elements[index - 1];
            if((secTer & SEC_TER_DELTA_FLAG) == 0) {
                // Primary CE just before p.
                p = secTer & 0xffffff00L;
                secTer = Collation.COMMON_SEC_AND_TER_CE;
            } else {
                // secTer = last secondary & tertiary for the previous primary
                index -= 2;
                for(;;) {
                    p = elements[index];
                    if((p & SEC_TER_DELTA_FLAG) == 0) {
                        p &= 0xffffff00L;
                        break;
                    }
                    --index;
                }
            }
        } else {
            // p > elements[index] which is the previous primary.
            // Find the last secondary & tertiary weights for it.
            p = q & 0xffffff00L;
            secTer = Collation.COMMON_SEC_AND_TER_CE;
            for(;;) {
                q = elements[++index];
                if((q & SEC_TER_DELTA_FLAG) == 0) {
                    // We must not be in a primary range.
                    assert((q & PRIMARY_STEP_MASK) == 0);
                    break;
                }
                secTer = q;
            }
        }
        return (p << 32) | (secTer & ~SEC_TER_DELTA_FLAG);
    }
764512
function ( buffers, geoInfo, facePositionIndexes, materialIndex, faceNormals, faceColors, faceUVs, faceWeights, faceWeightIndices, faceLength ) {

			for ( var i = 2; i < faceLength; i ++ ) {

				buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ 0 ] ] );
				buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ 1 ] ] );
				buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ 2 ] ] );

				buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ ( i - 1 ) * 3 ] ] );
				buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ ( i - 1 ) * 3 + 1 ] ] );
				buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ ( i - 1 ) * 3 + 2 ] ] );

				buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ i * 3 ] ] );
				buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ i * 3 + 1 ] ] );
				buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ i * 3 + 2 ] ] );

				if ( geoInfo.skeleton ) {

					buffers.vertexWeights.push( faceWeights[ 0 ] );
					buffers.vertexWeights.push( faceWeights[ 1 ] );
					buffers.vertexWeights.push( faceWeights[ 2 ] );
					buffers.vertexWeights.push( faceWeights[ 3 ] );

					buffers.vertexWeights.push( faceWeights[ ( i - 1 ) * 4 ] );
					buffers.vertexWeights.push( faceWeights[ ( i - 1 ) * 4 + 1 ] );
					buffers.vertexWeights.push( faceWeights[ ( i - 1 ) * 4 + 2 ] );
					buffers.vertexWeights.push( faceWeights[ ( i - 1 ) * 4 + 3 ] );

					buffers.vertexWeights.push( faceWeights[ i * 4 ] );
					buffers.vertexWeights.push( faceWeights[ i * 4 + 1 ] );
					buffers.vertexWeights.push( faceWeights[ i * 4 + 2 ] );
					buffers.vertexWeights.push( faceWeights[ i * 4 + 3 ] );

					buffers.weightsIndices.push( faceWeightIndices[ 0 ] );
					buffers.weightsIndices.push( faceWeightIndices[ 1 ] );
					buffers.weightsIndices.push( faceWeightIndices[ 2 ] );
					buffers.weightsIndices.push( faceWeightIndices[ 3 ] );

					buffers.weightsIndices.push( faceWeightIndices[ ( i - 1 ) * 4 ] );
					buffers.weightsIndices.push( faceWeightIndices[ ( i - 1 ) * 4 + 1 ] );
					buffers.weightsIndices.push( faceWeightIndices[ ( i - 1 ) * 4 + 2 ] );
					buffers.weightsIndices.push( faceWeightIndices[ ( i - 1 ) * 4 + 3 ] );

					buffers.weightsIndices.push( faceWeightIndices[ i * 4 ] );
					buffers.weightsIndices.push( faceWeightIndices[ i * 4 + 1 ] );
					buffers.weightsIndices.push( faceWeightIndices[ i * 4 + 2 ] );
					buffers.weightsIndices.push( faceWeightIndices[ i * 4 + 3 ] );

				}

				if ( geoInfo.color ) {

					buffers.colors.push( faceColors[ 0 ] );
					buffers.colors.push( faceColors[ 1 ] );
					buffers.colors.push( faceColors[ 2 ] );

					buffers.colors.push( faceColors[ ( i - 1 ) * 3 ] );
					buffers.colors.push( faceColors[ ( i - 1 ) * 3 + 1 ] );
					buffers.colors.push( faceColors[ ( i - 1 ) * 3 + 2 ] );

					buffers.colors.push( faceColors[ i * 3 ] );
					buffers.colors.push( faceColors[ i * 3 + 1 ] );
					buffers.colors.push( faceColors[ i * 3 + 2 ] );

				}

				if ( geoInfo.material && geoInfo.material.mappingType !== 'AllSame' ) {

					buffers.materialIndex.push( materialIndex );
					buffers.materialIndex.push( materialIndex );
					buffers.materialIndex.push( materialIndex );

				}

				if ( geoInfo.normal ) {

					buffers.normal.push( faceNormals[ 0 ] );
					buffers.normal.push( faceNormals[ 1 ] );
					buffers.normal.push( faceNormals[ 2 ] );

					buffers.normal.push( faceNormals[ ( i - 1 ) * 3 ] );
					buffers.normal.push( faceNormals[ ( i - 1 ) * 3 + 1 ] );
					buffers.normal.push( faceNormals[ ( i - 1 ) * 3 + 2 ] );

					buffers.normal.push( faceNormals[ i * 3 ] );
					buffers.normal.push( faceNormals[ i * 3 + 1 ] );
					buffers.normal.push( faceNormals[ i * 3 + 2 ] );

				}

				if ( geoInfo.uv ) {

					geoInfo.uv.forEach( function ( uv, j ) {

						if ( buffers.uvs[ j ] === undefined ) buffers.uvs[ j ] = [];

						buffers.uvs[ j ].push( faceUVs[ j ][ 0 ] );
						buffers.uvs[ j ].push( faceUVs[ j ][ 1 ] );

						buffers.uvs[ j ].push( faceUVs[ j ][ ( i - 1 ) * 2 ] );
						buffers.uvs[ j ].push( faceUVs[ j ][ ( i - 1 ) * 2 + 1 ] );

						buffers.uvs[ j ].push( faceUVs[ j ][ i * 2 ] );
						buffers.uvs[ j ].push( faceUVs[ j ][ i * 2 + 1 ] );

					} );

				}

			}

		}
382872
def _find_nn_pos_before_site(self, siteindex):
        
        alldist = [(self._mol.get_distance(siteindex, i), i)
                   for i in range(siteindex)]
        alldist = sorted(alldist, key=lambda x: x[0])
        return [d[1] for d in alldist]
1366754
def site_symbols(self):
        
        syms = [site.specie.symbol for site in self.structures[0]]
        return [a[0] for a in itertools.groupby(syms)]
410752
def get_lines(self):
        
        lines = [["{:f}".format(self._cluster[0].x),
                  "{:f}".format(self._cluster[0].y),
                  "{:f}".format(self._cluster[0].z),
                  0, self.absorbing_atom, "0.0", 0]]
        for i, site in enumerate(self._cluster[1:]):
            site_symbol = re.sub(r"[^aA-zZ]+", "", site.species_string)
            ipot = self.pot_dict[site_symbol]
            lines.append(["{:f}".format(site.x), "{:f}".format(site.y),
                          "{:f}".format(site.z), ipot, site_symbol,
                          "{:f}".format(self._cluster.get_distance(0, i + 1)), i + 1])

        return sorted(lines, key=itemgetter(5))
692652
def _secondary_values(self):
        """"""
        return [
            val for serie in self.secondary_series for val in serie.values
            if val is not None
        ]
941350
def _get_site_type_dummy_variables(self, sites):
        
        Ss = np.zeros((len(sites.vs30),))
        Sa = np.zeros((len(sites.vs30),))
        # Soft soil; Vs30 < 360 m/s. Page 199.
        idxSs = (sites.vs30 < 360.0)
        # Stiff soil Class A; 360 m/s <= Vs30 <= 750 m/s. Page 199.
        idxSa = (sites.vs30 >= 360.0) & (sites.vs30 <= 750.0)
        Ss[idxSs] = 1
        Sa[idxSa] = 1
        return Ss, Sa
516124
def valences(self):
        
        el = [site.species_string for site in self._structure.sites]
        valence_dict = dict(zip(el, self._valences))
        return valence_dict
58210
def _get_site_type_dummy_variables(self, sites):
        
        Sc = np.zeros_like(sites.vs30)
        Sd = np.zeros_like(sites.vs30)
        # Soft soil; Vs30 < 360 m/s. Page 199.
        Sd[sites.vs30 < 360.0] = 1
        # Stiff soil 360 <= Vs30 < 760
        Sc[np.logical_and(sites.vs30 >= 360.0, sites.vs30 < 760.0)] = 1

        return Sc, Sd