def parseLatticeString(text, facility):
    spaceChargeOn = facility.getSpaceChargeOn()
    multipart = facility.getMultipart()
    twiss = facility.getTwiss()
    beamdata = facility.getBeamdata()
    nbrOfSplits = facility.getNbrOfSplits()
    lattice = Lattice('ParsedLattice', beamdata, twiss, multipart)
    for line in iter(text.splitlines()):
        words = line.split()
        typeOfElem = words[0]
        name = words[1]
        l = float(words[words.index("L:") + 1]) #what comes after "L:"
        if typeOfElem == "cavity":
            cavityOscillations = float(words[words.index("Oscillations:") + 1])
            cavityAmplitudeA = float(words[words.index("AmplitudeA:") + 1])
            cavityAmplitudeB = float(words[words.index("AmplitudeB:") + 1])
            cavityE_0 = float(words[words.index("E_0:") + 1])
            cavitySigma = float(words[words.index("sigma:") + 1])
            cavityP = float(words[words.index("p:") + 1])

            cavityEzofs = [cavityOscillations, cavityAmplitudeA, cavityAmplitudeB, cavityE_0, cavitySigma, cavityP]
            elem = Cavity(name, l, cavityEzofs, beamdata, nbrOfSplits)
            lattice.appendElement(elem)
            continue
        if typeOfElem == "dipole":
            rho = float(words[words.index("rho:") + 1]) #what comes after "rho:"
            #k_x = what comes after "K_x: "
            #k_y = what comes after "K_y: " # not needed for construction
            beta = beamdata[0]
            nparam = float(words[words.index("nparam:") + 1]) #what comes after "nparam:"
            alpha = float(words[words.index("Alpha:") + 1]) #what comes after "Alpha:"
            #elem = Dipole(name, rho, alpha, nparam, spaceChargeOn, multipart, twiss, beamdata, nbrOfSplits)
            lattice.createDipole(name, rho, alpha, nparam)
            continue
        elif typeOfElem != "drift" and typeOfElem != "cavity":
            k = float(words[words.index("K:") + 1]) #what comes after "K:"
        if typeOfElem == "liealgelem":
            hamToUse = words[words.index("HamUsed:") + 1] #what comes after "HamUsed:" and before next whitespace
            order = int(words[words.index("Order:") + 1]) #what comes after "Order:"
            #elem = LieAlgElement(name, hamToUse, k, l, order, spaceChargeOn, multipart, twiss, beamdata, nbrOfSplits)
            lattice.createSextupole(name, k, l, order)
            continue
        
        if typeOfElem == "quad":
            #elem = Quad(name, k, l, spaceChargeOn, multipart, twiss, beamdata, nbrOfSplits)
            lattice.createQuadrupole(name, k, l)
            continue
        if typeOfElem == "drift":
            #elem = Drift(name, l, spaceChargeOn, multipart, twiss, beamdata, nbrOfSplits)
            lattice.createDrift(name, l)
            continue           
    return lattice
driftLength = 1.0
compDrift = Drift(driftName, driftLength, spaceChargeOnInComp, multipartfromold, twissfromold, beamdata, nbrOfSplits)
#compLattice.appendElement(compDrift)

dQName = "dQ"
dQuadLength = 0.4
dQuadStrength = 0.8
dQ = Quad(dQName, dQuadStrength, dQuadLength, spaceChargeOnInComp, multipartfromold, twissfromold, beamdata, nbrOfSplits)
#compLattice.appendElement(dQ)

sextuName = "sextu"
hamToUse = "sextupoleham"
sextuLength = 0.3
sextuStrength = 0.6
compOrder = 6
compLattice.createSextupole(sextuName, sextuStrength, sextuLength, compOrder)
#sextu = LieAlgElement(sextuName, hamToUse, sextuStrength, sextuLength, compOrder, spaceChargeOnInComp, multipartfromold, twissfromold, beamdata, nbrOfSplits)
#compLattice.appendElement(sextu)

#compLattice.appendElement(compDrift)

dipoleName = "dipole"
dipoleRho = 5
dipoleAlpha = math.pi/4 
dipolen = 0.5
compLattice.createDipole(dipoleName, dipoleRho, dipoleAlpha, dipolen)
#compDipole = Dipole(dipoleName, dipoleRho, dipoleAlpha, dipolen, spaceChargeOnInComp, multipartfromold, twissfromold, beamdata, nbrOfSplits)
#compLattice.appendElement(compDipole)

#compLattice.appendElement(fQ)
compLattice.createQuadrupole(fQName, fQuadStrength, fQuadLength)