Parses optimized XYZ coordinates. If not present, parses optimized Z-matrix.
421832
def _read_optimized_geometry(self):
        
        header_pattern = r"\*+\s+OPTIMIZATION\s+CONVERGED\s+\*+\s+\*+\s+Coordinates \(Angstroms\)\s+ATOM\s+X\s+Y\s+Z"
        table_pattern = r"\s+\d+\s+\w+\s+([\d\-\.]+)\s+([\d\-\.]+)\s+([\d\-\.]+)"
        footer_pattern = r"\s+Z-matrix Print:"

        parsed_optimized_geometry = read_table_pattern(
            self.text, header_pattern, table_pattern, footer_pattern)
        if parsed_optimized_geometry == [] or None:
            self.data["optimized_geometry"] = None
            header_pattern = r"^\s+\*+\s+OPTIMIZATION CONVERGED\s+\*+\s+\*+\s+Z-matrix\s+Print:\s+\$molecule\s+[\d\-]+\s+[\d\-]+\n"
            table_pattern = r"\s*(\w+)(?:\s+(\d+)\s+([\d\-\.]+)(?:\s+(\d+)\s+([\d\-\.]+)(?:\s+(\d+)\s+([\d\-\.]+))*)*)*(?:\s+0)*"
            footer_pattern = r"^\$end\n"

            self.data["optimized_zmat"] = read_table_pattern(
                self.text, header_pattern, table_pattern, footer_pattern)
        else:
            self.data["optimized_geometry"] = process_parsed_coords(
                parsed_optimized_geometry[0])
            if self.data.get('charge') != None:
                self.data["molecule_from_optimized_geometry"] = Molecule(
                    species=self.data.get('species'),
                    coords=self.data.get('optimized_geometry'),
                    charge=self.data.get('charge'),
                    spin_multiplicity=self.data.get('multiplicity'))
998143
def _parse_kpoint(line, lines):
    """"""
    toks = line.split()
    kpoint = [float(x) for x in toks[:3]]
    weight = float(toks[-1])
    newline = next(lines)

    bands_up = []
    occ_up = []
    bands_down = []
    occ_down = []
    ispin = None

    while len(newline.split()) > 0:
        toks = newline.split()
        if ispin is None:
            # there are two spins if there are 5 columns (two spin energies and occupancies) or
            # very probably if there are 3 columns and the last column's first value isn't 1.0
            # (which would be the occupancy of the lowest energy level)
            ispin = (len(toks) == 5) or (len(toks) == 3 and abs(float(toks[2]) - 1.0) > 1.0e-4)

        if len(toks) == 2:
            bands_up.append(float(toks[1]))
        elif len(toks) == 3 and not ispin:
            bands_up.append(float(toks[1]))
            occ_up.append(float(toks[2]))
        elif len(toks) == 3 and ispin:
            bands_up.append(float(toks[1]))
            bands_down.append(float(toks[2]))
        elif len(toks) == 5 and ispin:
            bands_up.append(float(toks[1]))
            bands_down.append(float(toks[2]))
            occ_up.append(float(toks[3]))
            occ_down.append(float(toks[4]))
        else:
            raise ValueError("Encountered {} when parsing k-point".format(newline))
        newline = next(lines)

    res = {"kpoint": kpoint, "weight": weight}
    if len(bands_down) > 0:
        res["energies"] = list(zip(bands_up, bands_down))
    else:
        res["energies"] = list(zip(bands_up))

    if len(occ_down) > 0:
        res["occupancies"] = list(zip(occ_up, occ_down))
    elif len(occ_up) > 0:
        res["occupancies"] = list(zip(occ_up))
      
    return res
547212
def xyz(self, idx):
        
        # Not implemented for Python 3:
        # GetBinXYZ(i, x, y, z)
        nx  = self.GetNbinsX() + 2
        ny  = self.GetNbinsY() + 2
        ndim = self.GetDimension()
        if ndim < 2:
            binx = idx % nx
            biny = 0
            binz = 0
        elif ndim < 3:
            binx = idx % nx
            biny = ((idx - binx) // nx) % ny
            binz = 0
        elif ndim < 4:
            binx = idx % nx
            biny = ((idx - binx) // nx) % ny
            binz = ((idx - binx) // nx - biny) // ny
        else:
            raise NotImplementedError
        return binx, biny, binz
326929
public static Double getMaxZ(Geometry geom) {
        if (geom != null) {
            return CoordinateUtils.zMinMax(geom.getCoordinates())[1];
        } else {
            return null;
        }
    }
1172203
def _compute_zs_mat(sz:TensorImageSize, scale:float, squish:float,
                   invert:bool, row_pct:float, col_pct:float)->AffineMatrix:
    ""
    orig_ratio = math.sqrt(sz[1]/sz[0])
    for s,r,i in zip(scale,squish, invert):
        s,r = 1/math.sqrt(s),math.sqrt(r)
        if s * r <= 1 and s / r <= 1: #Test if we are completely inside the picture
            w,h = (s/r, s*r) if i else (s*r,s/r)
            col_c = (1-w) * (2*col_pct - 1)
            row_c = (1-h) * (2*row_pct - 1)
            return _get_zoom_mat(w, h, col_c, row_c)

    #Fallback, hack to emulate a center crop without cropping anything yet.
    if orig_ratio > 1: return _get_zoom_mat(1/orig_ratio**2, 1, 0, 0.)
    else:              return _get_zoom_mat(1, orig_ratio**2, 0, 0.)
1104580
public void convertToSparse() {
        switch ( mat.getType() ) {
            case DDRM: {
                DMatrixSparseCSC m = new DMatrixSparseCSC(mat.getNumRows(), mat.getNumCols());
                ConvertDMatrixStruct.convert((DMatrixRMaj) mat, m,0);
                setMatrix(m);
            } break;
            case FDRM: {
                FMatrixSparseCSC m = new FMatrixSparseCSC(mat.getNumRows(), mat.getNumCols());
                ConvertFMatrixStruct.convert((FMatrixRMaj) mat, m,0);
                setMatrix(m);
            } break;

            case DSCC:
            case FSCC:
                break;
            default:
                throw new RuntimeException("Conversion not supported!");
        }
    }
1272450
public Yytoken yylex() throws java.io.IOException, ParseException {
    int zzInput;
    int zzAction;

    // cached fields:
    int zzCurrentPosL;
    int zzMarkedPosL;
    int zzEndReadL = zzEndRead;
    char [] zzBufferL = zzBuffer;
    char [] zzCMapL = ZZ_CMAP;

    int [] zzTransL = ZZ_TRANS;
    int [] zzRowMapL = ZZ_ROWMAP;
    int [] zzAttrL = ZZ_ATTRIBUTE;

    while (true) {
      zzMarkedPosL = zzMarkedPos;

      yychar+= zzMarkedPosL-zzStartRead;

      zzAction = -1;

      zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
  
      zzState = ZZ_LEXSTATE[zzLexicalState];


      zzForAction: {
        while (true) {
    
          if (zzCurrentPosL < zzEndReadL)
            zzInput = zzBufferL[zzCurrentPosL++];
          else if (zzAtEOF) {
            zzInput = YYEOF;
            break zzForAction;
          }
          else {
            // store back cached positions
            zzCurrentPos  = zzCurrentPosL;
            zzMarkedPos   = zzMarkedPosL;
            boolean eof = zzRefill();
            // get translated positions and possibly new buffer
            zzCurrentPosL  = zzCurrentPos;
            zzMarkedPosL   = zzMarkedPos;
            zzBufferL      = zzBuffer;
            zzEndReadL     = zzEndRead;
            if (eof) {
              zzInput = YYEOF;
              break zzForAction;
            }
            else {
              zzInput = zzBufferL[zzCurrentPosL++];
            }
          }
          int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
          if (zzNext == -1) break zzForAction;
          zzState = zzNext;

          int zzAttributes = zzAttrL[zzState];
          if ( (zzAttributes & 1) == 1 ) {
            zzAction = zzState;
            zzMarkedPosL = zzCurrentPosL;
            if ( (zzAttributes & 8) == 8 ) break zzForAction;
          }

        }
      }

      // store back cached position
      zzMarkedPos = zzMarkedPosL;

      switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
        case 11: 
          { sb.append(yytext());
          }
        case 25: break;
        case 4: 
          { sb = null; sb = new StringBuffer(); yybegin(STRING_BEGIN);
          }
        case 26: break;
        case 16: 
          { sb.append('\b');
          }
        case 27: break;
        case 6: 
          { return new Yytoken(Yytoken.TYPE_RIGHT_BRACE,null);
          }
        case 28: break;
        case 23: 
          { Boolean val=Boolean.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val);
          }
        case 29: break;
        case 22: 
          { return new Yytoken(Yytoken.TYPE_VALUE, null);
          }
        case 30: break;
        case 13: 
          { yybegin(YYINITIAL);return new Yytoken(Yytoken.TYPE_VALUE, sb.toString());
          }
        case 31: break;
        case 12: 
          { sb.append('\\');
          }
        case 32: break;
        case 21: 
          { Double val=Double.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val);
          }
        case 33: break;
        case 1: 
          { throw new ParseException(yychar, ParseException.ERROR_UNEXPECTED_CHAR, new Character(yycharat(0)));
          }
        case 34: break;
        case 8: 
          { return new Yytoken(Yytoken.TYPE_RIGHT_SQUARE,null);
          }
        case 35: break;
        case 19: 
          { sb.append('\r');
          }
        case 36: break;
        case 15: 
          { sb.append('/');
          }
        case 37: break;
        case 10: 
          { return new Yytoken(Yytoken.TYPE_COLON,null);
          }
        case 38: break;
        case 14: 
          { sb.append('"');
          }
        case 39: break;
        case 5: 
          { return new Yytoken(Yytoken.TYPE_LEFT_BRACE,null);
          }
        case 40: break;
        case 17: 
          { sb.append('\f');
          }
        case 41: break;
        case 24: 
          { try{
														int ch=Integer.parseInt(yytext().substring(2),16);
														sb.append((char)ch);
													}
													catch(Exception e){
														throw new ParseException(yychar, ParseException.ERROR_UNEXPECTED_EXCEPTION, e);
													}
          }
        case 42: break;
        case 20: 
          { sb.append('\t');
          }
        case 43: break;
        case 7: 
          { return new Yytoken(Yytoken.TYPE_LEFT_SQUARE,null);
          }
        case 44: break;
        case 2: 
          { Long val=Long.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val);
          }
        case 45: break;
        case 18: 
          { sb.append('\n');
          }
        case 46: break;
        case 9: 
          { return new Yytoken(Yytoken.TYPE_COMMA,null);
          }
        case 47: break;
        case 3: 
          { 
          }
        case 48: break;
        default: 
          if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
            zzAtEOF = true;
            return null;
          } 
          else {
            zzScanError(ZZ_NO_MATCH);
          }
      }
    }
  }
1025781
def get_SZ(self, psd, geometry):
        
        if (self._S_table is None) or (self._Z_table is None):
            raise AttributeError(
                "Initialize or load the scattering table first.")

        if (not isinstance(psd, PSD)) or self._previous_psd != psd:
            self._S_dict = {}
            self._Z_dict = {}
            psd_w = psd(self._psd_D)

            for geom in self.geometries:
                self._S_dict[geom] = \
                    trapz(self._S_table[geom] * psd_w, self._psd_D)
                self._Z_dict[geom] = \
                    trapz(self._Z_table[geom] * psd_w, self._psd_D)

            self._previous_psd = psd

        return (self._S_dict[geometry], self._Z_dict[geometry])
439727
def spin_z_op(param, oper):
    """"""
    slaves = param['slaves']
    oper['Sz'] = np.array([spin_z(slaves, spin) for spin in range(slaves)])
    oper['Sz+1/2'] = oper['Sz'] + 0.5*np.eye(2**slaves)
    oper['sumSz2'] = oper['Sz'].sum(axis=0)**2  # because Sz is diagonal
    Sz_mat_shape = oper['Sz'].reshape(param['orbitals'], 2, 2**slaves, 2**slaves)
    oper['sumSz-sp2'] = (Sz_mat_shape.sum(axis=1)**2).sum(axis=0)
    oper['sumSz-or2'] = (Sz_mat_shape.sum(axis=0)**2).sum(axis=0)
174490
def translate_z(self, d):
        
        mat = numpy.array([
            [1, 0, 0, 0],
            [0, 1, 0, 0],
            [0, 0, 1, 0],
            [0, 0, d, 1]
        ])
        self.vectors = self.vectors.dot(mat)
        return self
382507
def parse(node)
      @fill_color = DocxColor.new(parent: self).parse(node)
      node.xpath('*').each do |node_child|
        case node_child.name
        when 'xfrm'
          @shape_size = DocxShapeSize.new(parent: self).parse(node_child)
        when 'prstGeom'
          @preset_geometry = PresetGeometry.new(parent: self).parse(node_child)
        when 'txbx'
          @text_box = TextBox.parse_list(node_child)
        when 'ln'
          @line = DocxShapeLine.new(parent: self).parse(node_child)
        when 'blipFill'
          @blip_fill = BlipFill.new(parent: self).parse(node_child)
        when 'custGeom'
          @preset_geometry = PresetGeometry.new(parent: self).parse(node_child)
          @preset_geometry.name = :custom
          @custom_geometry = OOXMLCustomGeometry.new(parent: self).parse(node_child)
        end
      end
      self
    end
1156295
function parsePolygonGeometry(coordinates) {
		var polygonWkt = [];
		for (var i = 0; i < coordinates.length; i++) {
			polygonWkt.push('(' + parseLineGeometry(coordinates[i]) + ')');
		}
		return polygonWkt.join(', ');
	}
1304371
def parse_text(file_name):
    """"""

    # Read the header
    fid = open(file_name, 'r')
    point_names = np.array(fid.readline().split())[2:-1:3]
    fid.close()
    for i in range(len(point_names)):
        point_names[i] = point_names[i][0:-2]

    # Read the matrix data
    S = np.loadtxt(file_name, skiprows=1)
    field = np.uint(S[:, 0])
    times = S[:, 1]
    S = S[:, 2:]

    # Set the -9999.99 markers to be not present
    S[S==-9999.99] = np.NaN

    # Store x, y and z in different arrays
    points = []
    points.append(S[:, 0:-1:3])
    points.append(S[:, 1:-1:3])
    points.append(S[:, 2:-1:3])

    return points, point_names, times
15336
def _xy_locs(mask):
  """"""
  y, x = mask.nonzero()
  return list(zip(x, y))
1363024
private float[] LABtoXYZ(float L, float a, float b, float[] xyzResult) {
        // Significant speedup: Removing Math.pow
        float y = (L + 16.0f) / 116.0f;
        float y3 = y * y * y; // Math.pow(y, 3.0);
        float x = (a / 500.0f) + y;
        float x3 = x * x * x; // Math.pow(x, 3.0);
        float z = y - (b / 200.0f);
        float z3 = z * z * z; // Math.pow(z, 3.0);

        if (y3 > 0.008856f) {
            y = y3;
        }
        else {
            y = (y - (16.0f / 116.0f)) / 7.787f;
        }

        if (x3 > 0.008856f) {
            x = x3;
        }
        else {
            x = (x - (16.0f / 116.0f)) / 7.787f;
        }

        if (z3 > 0.008856f) {
            z = z3;
        }
        else {
            z = (z - (16.0f / 116.0f)) / 7.787f;
        }

        xyzResult[0] = x * whitePoint[0];
        xyzResult[1] = y * whitePoint[1];
        xyzResult[2] = z * whitePoint[2];

        return xyzResult;
    }
526918
def parseSpectra(self):
        
        #Note: the spectra need to be iterated completely to save the
        #metadataNode
        if self._parsed:
            raise TypeError('Mzml file already parsed.')
        self._parsed = True
        return self._parseMzml()
324471
def _xy_idx(self):
        

        yidx, xidx = np.indices(self._data.shape)
        return xidx[~self.mask].ravel(), yidx[~self.mask].ravel()