def eBeamSphere(numPolymersPerSphere, numPEG, numHPMA, FZ1, FMinRadius1, FZ2, FMinRadius2, AtomicMinDist, bondLength, filename, SphereBBG, PolyGen, centerPos): # generate the root points in the spherical inner shell SphereBB = SphereBBG.generateBuildingBlock(numPolymersPerSphere, FZ2, -90, 90, -180, 180, FMinRadius2) SphereBB.transformBBToLabFrame(np.array([0.0, 0.0, 1.0]), centerPos, 0.0) SpherePoints = SphereBB.blockXYZVals directors = [(pos - centerPos) / np.linalg.norm(pos - centerPos) for pos in SpherePoints] allNames = [] curStrand = 0 for director, pos in zip(directors, SpherePoints): print curStrand, " out of ", len(SpherePoints) strand = generateEBeamPolymer(numPEG, numHPMA, PolyGen, FZ1, FMinRadius1, FZ2, FMinRadius2, AtomicMinDist, bondLength) strand.transformBBToLabFrame(director, pos, 0.0) if curStrand == 0: xyzVals = strand.blockXYZVals allNames = strand.blockAtomNames else: xyzVals = np.concatenate((xyzVals, strand.blockXYZVals), 0) allNames = np.concatenate((allNames, strand.blockAtomNames), 0) curStrand += 1 fIO.saveXYZList(xyzVals, allNames, filename)
def polyCubes(PosList, DirList, numPolymersPerCube, X, Y, Z, thetad1, thetad2, phid1, phid2, polymerCylinderDiam, polymerCylinderLength, numSpheresPerParticle, numMonomers, Alpha1, Alpha2, Beta1, Beta2, PolyGen, filename): # compute some universal vals envelopeList = [ 'frustum ' + str(polymerCylinderLength) + ' ' + str(polymerCylinderDiam / 2.0) + ' ' + str(-polymerCylinderDiam) + ' ' + str(polymerCylinderDiam) ] polymerStartPoint = np.array([0.0, 0.0, polymerCylinderDiam]) bondLength = polymerCylinderLength / numMonomers curStrand = 0 for Pos, Dirn in zip(PosList, DirList): # generate a building block containing the positions and orientations of the polymer envelopes. Cuboid_BB = CuboidPackSCBBG.generateBuildingBlock( numPolymersPerCube, X, Y, Z, thetad1, thetad2, phid1, phid2, polymerCylinderDiam, polymerCylinderLength, numSpheresPerParticle) # transform the positions and director of the building block to the current cube in the lattice. Cuboid_BB.transformBBToLabFrame(Dirn, Pos, 0.0) # extract the start position and director for each polymer from the building block PolyStartPoints = Cuboid_BB.blockXYZVals[0:-1:2] PolyDirectors = [(PosB - PosA) / np.linalg.norm(PosB - PosA) for PosA, PosB in zip(Cuboid_BB.blockXYZVals[0:-1:2], Cuboid_BB.blockXYZVals[1:-1:2])] # compute a polymer for each position, director pair in the building block. build the list across all the cubes. for director, pos in zip(PolyDirectors, PolyStartPoints): print curStrand, " out of ", len(PolyStartPoints) * len( PosList), " polymers of type ", filename # compute a polymer that fits in a simple envelope with the given polymer parameters Polymer = PolyGen.generateBuildingBlock(numMonomers, polymerStartPoint, Alpha1, Alpha2, Beta1, Beta2, polymerCylinderDiam, bondLength, envelopeList=envelopeList, visualiseEnvelope=(0, 100)) Polymer.setBlockRefPoint(polymerStartPoint) # transform the polymer to the correct positions and orientation Polymer.transformBBToLabFrame(director, pos, 0.0) # append the xyzvals and names of each sphere to a mega list if curStrand == 0: xyzVals = Polymer.blockXYZVals allNames = Polymer.blockAtomNames else: xyzVals = np.concatenate((xyzVals, Polymer.blockXYZVals), 0) allNames = np.concatenate((allNames, Polymer.blockAtomNames), 0) curStrand += 1 fIO.saveXYZList(xyzVals, allNames, filename)
def exportBBK(self, fileroot): fIO.saveXYZList(self.blockXYZVals, self.blockAtomNames, fileroot + '.xyz') line1 = "floatlist blockRefPoint " + str(self.blockRefPoint[0]) + " " + str(self.blockRefPoint[1]) + " " + str(self.blockRefPoint[2]) + "\n" line2 = "floatlist blockOrientation " + str(self.blockDirectorHat[0]) + " " + str(self.blockDirectorHat[1]) + " " + str(self.blockDirectorHat[2]) + "\n" lines = "intlist blockConnectors" for connection in self.blockConnectors: lines += " " + str(connection[0]) + " " + str(connection[1]) + " " + str(connection[2]) lines +='\n' fIO.writeTextFile([line1, line2, lines], fileroot + '.bbk')
def generateBuildingBlockXYZ(self): print("Generate initial conformation.") xyzVals = self.generateSpaceCurve() if self.dumpInterimFiles == 1: fIO.saveXYZList(xyzVals, self.blockNames, 'initialChain.xyz') print("Minimising End Point with dihedral moves on allowed list") # perform the energy minimisation that moves the free end to pointB xyzVals = self.minimiseEnergy(xyzVals) if self.dumpInterimFiles == 1: fIO.saveXYZList(xyzVals, self.blockNames, 'pointBMinimised.xyz') print("Randomising chain using crankshaft moves.") xyzVals, numValidMoves = self.crankShaftMoves(xyzVals, self.numCrankMoves, 1) if self.dumpInterimFiles == 1 and self.numCrankMoves > 0: fIO.saveXYZList(xyzVals, self.blockNames, 'crankedChain.xyz') print("Folding structure up.") xyzVals = self.foldInsideEnvelope(xyzVals) if self.dumpInterimFiles == 1: fIO.saveXYZList(xyzVals, self.blockNames, 'foldedChain.xyz') return xyzVals
def constructLoop(self, BB1, BB2, loopGen, pointsToAvoid): connectorA = BB1.getConnectionAtoms( 1) # 1 is the C terminus of interest connectorB = BB2.getConnectionAtoms( 0) # 0 is the N terminus of interest # generate TNB frames at either connector TNBA = coords.constructTNBFrame(connectorA[0], connectorA[1], connectorA[2]) TNBB = coords.constructTNBFrame(connectorB[0], connectorB[1], connectorB[2]) # C terminus is CCN triad (new atom will be an N). betaA = self.angleC alphaA = self.phi # N Terminus is CNC triad. (new atom will be a C). betaB = self.angleN alphaB = self.psi # compute the coil start and end points pointA = connectorA[2] + self.CNbondLength * coords.generateTNBVecXYZ( TNBA, betaA, alphaA) pointB = connectorB[2] + self.CNbondLength * coords.generateTNBVecXYZ( TNBB, betaB, alphaB) if self.dumpInterimFiles: fIO.saveXYZList([pointA, connectorA[2], pointB, connectorB[2]], ['Ca', 'S', 'O', 'S'], 'connectionDetails.xyz') fIO.saveXYZ(pointsToAvoid, 'K', 'pointsToAvoid.xyz') numCrankMoves = 0 if self.parallel: iSphereR = 0.4 * self.strandLength * 3.5 else: iSphereR = 0.9 * self.betaStrandSeparation / 2.0 # create the loop building Blockss return loopGen.generateBuildingBlock( self.numLoopResidues, pointA, pointB, self.minDist, numCrankMoves, pointsToAvoid=pointsToAvoid, envelopeList=["innersphere " + str(iSphereR)])
def generateBuildingBlockXYZ(self): print "Generating initial conformation in blockspace." xyzVals = self.generateSpaceCurve() if self.dumpInterimFiles == 1: self.blockNames = self.generateBuildingBlockNames() fIO.saveXYZList(xyzVals, self.blockNames, 'chainConnectedPointB.xyz') # clean up Zeros xyzVals = self.cleanUpZeroes(xyzVals) print "Randomising chain using crankshaft moves." xyzVals = self.crankShaftMoves(xyzVals, self.numCrankMoves, 1) if self.dumpInterimFiles == 1 and self.numCrankMoves > 0: fIO.saveXYZList(xyzVals, self.blockNames, 'crankedChain.xyz') print "Visualising envelope" self.visualiseEnvelope(10000, 20.0, 20.0, 20.0) print "Ensuring structure is inside envelope" xyzVals = self.foldInsideEnvelope(xyzVals) if self.dumpInterimFiles == 1: fIO.saveXYZList(xyzVals, self.blockNames, 'foldedChain.xyz') return xyzVals
def generateSpaceCurve(self): # Over-rides the generate space curve function of the parent to generate a peptide backbone # and a pseudo energy landscape approach to find an initial chain with the end point fixed # at point B. # create a regular b0a14ckBone using block Points A as the first residue peptideBackbone = self.PBG.generateBuildingBlock( self.numResidues, seedResidue=self.blockPointsA) if self.dumpInterimFiles == 1: fIO.saveXYZList(peptideBackbone.blockXYZVals, peptideBackbone.blockAtomNames, 'initialPeptideBackbone.xyz') # extract the xyzValues xyzVals = peptideBackbone.getAtomsXYZ() # perform the energy minimisation that moves the free end to blockPointsB xyzVals = self.minimiseEnergy(xyzVals, self.allowedList) if self.dumpInterimFiles == 1: fIO.saveXYZ(xyzVals, 'K', 'chainConnectedBlockFrame.xyz') return xyzVals
envelopeList=innerEnvelopeList, visualiseEnvelope=(envelopeSize, 400, 'innerEnvelope.xyz')) strand.setBlockRefPoint(innerPolymerStartPoint) strand.blockAtomNames = names[:] strand.exportBBK("inner_strand_" + str(strandNum)) innerPolymerStrands.append(strand) AllNames = [] curStrand = 0 for director, pos, strand in zip(outerDirectorsHat, PolymerSphereOuterPoints, outerPolymerStrands): strand.transformBBToLabFrame(director, pos, 0.0) if curStrand == 0: xyzVals = strand.blockXYZVals allNames = strand.blockAtomNames else: xyzVals = np.concatenate((xyzVals, strand.blockXYZVals), 0) allNames = np.concatenate((allNames, strand.blockAtomNames), 0) curStrand += 1 for director, pos, strand in zip(innerDirectorsHat, PolymerSphereInnerPoints, innerPolymerStrands): strand.transformBBToLabFrame(director, pos, 0.0) xyzVals = np.concatenate((xyzVals, strand.blockXYZVals), 0) allNames = np.concatenate((allNames, strand.blockAtomNames), 0) curStrand += 1 fIO.saveXYZList(xyzVals, allNames, "Vesicle.xyz") print "classic vesicle example done"
# generate backbone realtime parameters numPoints = 100 pointA = 11.0 * np.array( [1.0 / np.sqrt(3.0), 1.0 / np.sqrt(3.0), 1.0 / np.sqrt(3)]) pointB = 11.0 * np.array( [-1.0 / np.sqrt(3.0), -1.0 / np.sqrt(3.0), -1.0 / np.sqrt(3)]) minDist = 1.0 bondLength = 1.5 crankMoves = 20 spherePointGenerator = EPBBG('../../Library/EllipsoidPacking.txt') spherePoints = spherePointGenerator.generateBuildingBlock( 30, 11, 11, 11, -90, 90, -180, 180, 4) pointsToAvoid = spherePoints.getAtomsXYZ() fIO.saveXYZList([pointA, pointB], ['Ca', 'O'], 'labPoints.xyz') fIO.saveXYZ(pointsToAvoid, 'Na', 'labPointsToAvoid.xyz') # generate a curve between the speicifed points ConstrainedPolymerPackBB = ConstrainedPolymerPackGBB.generateBuildingBlock( numPoints, pointA, pointB, minDist, bondLength, crankMoves, envelopeList=["outersphere 12.0", "innersphere 10.0"], pointsToAvoid=pointsToAvoid) ConstrainedPolymerPackGBB.checkBondLengths() ConstrainedPolymerPackBB.exportBBK(fIO.fileRootFromInfile(filename, 'txt')) print "constrainedPolymer Done"
def generateBuildingBlockXYZ(self): # The spidroin model consists of two alpha helical termini proteins which are taken from PDB files # and a long coil of about 3000 residues between them. The long coil is a random chain that must fit inside # a frustum so that it can pack together in a sphere. # # The centre of mass of the two termini are placed at +/- spidroinTerminusSeparation/2.0 on the x axis. print "CTerminus" refPosCTerm = np.array( [-self.spidroinTerminusSeparation / 2.0, 0.0, 0.0]) self.CTerminus = self.CTerminusGen.generateBuildingBlock( director=self.CTermDirectorHat, showBlockDirector=False) self.CTerminus.transformBBToLabFrame(self.spidroinDirector, refPosCTerm, self.CTermRot) if self.nameByBuildingBlockType: self.CTerminus.replaceNames(self.CTerminalAtomName) print "NTerminus" refPosNTerm = np.array( [self.spidroinTerminusSeparation / 2.0, 0.0, 0.0]) self.NTerminus = self.NTerminusGen.generateBuildingBlock( director=self.NTermDirectorHat, showBlockDirector=False) self.NTerminus.transformBBToLabFrame(self.spidroinDirector, refPosNTerm, self.NTermRot) if self.nameByBuildingBlockType: self.NTerminus.replaceNames(self.NTerminalAtomName) # accumulate a pointsToAvoid array as we go. pointsToAvoid = self.NTerminus.blockXYZVals + self.CTerminus.blockXYZVals if self.dumpInterimFiles == 1: fIO.saveXYZ(self.NTerminus.blockXYZVals, self.NTerminalAtomName, "NTerminal.xyz") fIO.saveXYZ(self.CTerminus.blockXYZVals, self.CTerminalAtomName, "CTerminal.xyz") print "constructing BetaSheets" numLoopResidues = 0 betaSheetOffset = np.array([0.0, 0.0, 0.0]) # construct correct number of antiparallel betasheet building blocks without any loops self.betaSheetBBs = [ self.BetasheetG.generateBuildingBlock(self.numBetaStrands, self.betaStrandLength, numLoopResidues, self.minDist, self.inStrandDirectorHat, self.crossStrandDirectorHat, betaSheetOffset, parallel=False) for n in range(0, self.numBetasheets) ] # compute the longest distance available in the beta sheet. # This is the mindist between the centre of mass of two beta sheets # and twice the distance of the betasheet centre of mass from the geometric boundary. # add two to the betaStrandLength to cope with the connection points betasheetSeparation = np.sqrt(( (self.betaStrandLength + 2) * self.betaStrandLengthPerResidue)**2 + (self.numBetaStrands * self.betaStrandSeparation)**2) # inhibit beta sheets from being closer than betaSheetSeparation/2 from the boundary where the coil cannot go. betaEnvelope = [ 'betasphere ' + str(self.betaSphereCenterZ) + ' ' + str(self.betaSphereRadius) ] # envelopeList=['None'] # useful line to have around to override envelope for debugging # compute a large box which surrounds the beta sheet zone XRange = [-1.5 * self.betaSphereRadius, 1.5 * self.betaSphereRadius] YRange = [-1.5 * self.betaSphereRadius, 1.5 * self.betaSphereRadius] ZRange = [self.betaSphereCenterZ - 1.5 * self.betaSphereRadius, 0] # calculate the positions of the centre of masses of the beta sheets within the beta envelope betaSheetCOMBB = self.SPBBG.generateBuildingBlock( self.numBetasheets, XRange, YRange, ZRange, betasheetSeparation, visualiseEnvelope=(10000, 2 * self.betaSphereRadius), envelopeList=betaEnvelope) betaSheetDirectors = [] # create beta sheet directors for n in range(0, self.numBetasheets): theta, phi = coords.pickRandomPointOnUnitSphere() betaSheetDirectors.append( coords.sphericalPolar2XYZ(np.array([1.0, theta, phi]))) print "Transform Beta Sheet locations" for director, com, betaSheetBB in zip(betaSheetDirectors, betaSheetCOMBB.blockXYZVals, self.betaSheetBBs): betaSheetBB.transformBBToLabFrame(director, com, 0) # rename the atoms in the betasheets if the flag is set if self.nameByBuildingBlockType: for bsheet in self.betaSheetBBs: bsheet.replaceNames(self.betaStrandAtomName) # add the beta sheets to the pointsToAvoid List for betaSheetBB in self.betaSheetBBs: pointsToAvoid = np.concatenate( (pointsToAvoid, betaSheetBB.blockXYZVals), 0) if self.dumpInterimFiles == 1 and self.numBetasheets > 0: # compile the beta sheets into a single entity and dump to file - for debug betaSheets = self.betaSheetBBs[0].blockXYZVals for betaSheet in self.betaSheetBBs[1:]: betaSheets = np.concatenate( (betaSheets, betaSheet.blockXYZVals), 0) fIO.saveXYZ(betaSheets, self.betaStrandAtomName, "betaSheet.xyz") print "Constructing Coils" # Compute the coil start (A) and end (B) points. # Define points m2, m1 and m0 for the s2, s1 and s0 end points of the coil. # ensure a realistic join. There is enough space at the end of the termini to not check for clashes. # The betasheetseparation is increased by 1 residue longer than the strand length to help with this. # find the C-terminus end of the N terminus and calculate where the coil should start ConnectionA = self.NTerminus.getConnectionAtoms(1) # N (psi) C (phi) C (omega) N (psi) C (phi) C connection # s0 s1 s2 m2 m1 m0 # a C to N terminus connection pointsA = self.findCoilPoints(ConnectionA[0], ConnectionA[1], ConnectionA[2], self.CNbondLength, self.CNbondLength, self.CCbondLength, self.phi, self.angleC, self.omega, self.angleN, self.psi, self.angleC) # find the N-terminus end of the C terminus and calculate where the coil should start ConnectionB = self.CTerminus.getConnectionAtoms(0) # C (phi) C (omega) N (psi) C (phi) C (omega) N connection # s0 s1 s2 m2 m1 m0 # an N to C terminus connection pointsB = self.findCoilPoints(ConnectionB[0], ConnectionB[1], ConnectionB[2], self.CNbondLength, self.CCbondLength, self.CNbondLength, self.omega, self.angleN, self.psi, self.angleC, self.phi, self.angleC) betaSheetNPoints = [] betaSheetCPoints = [] # Determine the connector atoms that define the seed points for each coil. # and make a list of the seed points for each free end of coil. # We make an assumption that there are no other beta strand in the vicinity of each beta stranf. # We can help to ensure this by defining an outer sphere when we come to make each coil link to inhibit # the coils from straying too far from the direct path between the end points. for betaSheetBB in self.betaSheetBBs: # get a list of all the connectors for the current beta sheet. # always alternating with N then C terminal connectors depending on how many strands for n in range(0, len(betaSheetBB.getAllConnectionIndices())): connector = betaSheetBB.getConnectionAtoms(n) if n % 2 == 1: # C terminus of beta strand. # compute m0, m1 and m2 in a sub list and append that to the list of coil points # N (psi) C (phi) C (omega) N (psi) C (phi) C connection # s0 s1 s2 m2 m1 m0 betaSheetCPoints.append( self.findCoilPoints( connector[0], connector[1], connector[2], self.CNbondLength, self.CNbondLength, self.CCbondLength, self.phi, self.angleC, self.omega, self.angleN, self.psi, self.angleC)) else: # N Terminus of beta strand # C (phi) C (omega) N (psi) C (phi) C (omega) N connection # s0 s1 s2 m2 m1 m0 betaSheetNPoints.append( self.findCoilPoints(connector[0], connector[1], connector[2], self.CNbondLength, self.CCbondLength, self.CNbondLength, self.omega, self.angleN, self.psi, self.angleC, self.phi, self.angleC)) # seed the coil point list with the global N and C termini of the coil coilPoints = [(pointsA, pointsB) ] # coil pair goes from C terminus to N terminus # so pair[0] is C, pair[1] is N if self.numBetasheets > 0: # find a valid order of cyling through the connectors COrderIndex, NOrderIndex = self.findValidPairOrder( self.numBetasheets, self.numBetaStrands) # Re order N and C points with the chosen valid index order betaSheetNPoints = [ betaSheetNPoints[index] for index in NOrderIndex ] betaSheetCPoints = [ betaSheetCPoints[index] for index in COrderIndex ] # loop through each CPoint, NPoint pair (which will be randomised throughout all the # beta sheets) to make a master list of connections to connect with a randomcoil for CPoint, NPoint in zip(betaSheetCPoints, betaSheetNPoints): newCoilEntry = ( coilPoints[-1][0], NPoint ) # the previous C terminus going to a new N terminus. coilPoints[-1] = ( CPoint, coilPoints[-1][1] ) # a new C terminus going to the last N terminus. coilPoints.insert( -1, newCoilEntry ) # insert the new coil points at the end of the list. if self.dumpInterimFiles == 1: coilPointsXYZ = [] coilPointNames = [] curConnection = 0 names = ['H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'Ne', 'K' ] # define 10 atoms for 10 colours and then cycle colours # dump all the coilPoints. Colour each pair it's own color to help ID the connectors. for coilPair in coilPoints: for coilConnector in coilPair: coilPointsXYZ += coilConnector #coilPointNames += ['H', 'He', 'Li'] coilPointNames += [ names[curConnection % 10], names[curConnection % 10], names[curConnection % 10] ] curConnection += 1 fIO.saveXYZList(coilPointsXYZ, coilPointNames, "CoilConnectors.xyz") print "Generating Coils" # The total length of the chain is to be broken up into chunks, each of which # must be long enough to reach the next point. We take betaStrandLengthPerResidue as the minimum # length of residue and compute the approximate number of residues needed to reach # between each pair of points in a straight line. spatialDistanceBetweenPoints = [ np.linalg.norm(pair[0][2] - pair[1][2]) for pair in coilPoints ] minVals = [ 2 * int(np.ceil(length / self.betaStrandLengthPerResidue)) for length in spatialDistanceBetweenPoints ] numResiduesInBetaStrands = numBetasheets * self.numBetaStrands * self.betaStrandLength numResiduesInTermini = int( float(self.NTerminus.countAtoms()) / 3.0 + float(self.CTerminus.countAtoms()) / 3.0) numResiduesToDivideUp = self.numResiduesCoil - numResiduesInBetaStrands - numResiduesInTermini if numResiduesToDivideUp < sum(minVals): print "Warning: Not enough residues for minimal coil connections." coilLengths = self.divideTotalSumEvenlyAmongListOfGroups( numResiduesToDivideUp, minVals) numCrankMoves = 0 # generate a random coil between each terminus adding the final loop to pointsToAvoid. # make sure it's inside the global frustum and also inside the local sphere defined by the distance # between the connection points. self.hairpinBBs = [] for coil, coilLength, distance in zip(coilPoints, coilLengths, spatialDistanceBetweenPoints): envelopeList = [ 'frustum ' + str(self.SpidroinFrustumZ1) + ' ' + str(self.SpidroinFrustumMaxRadius) + ' ' + str(self.SpidroinFrustumZ2) + ' ' + str(self.SpidroinFrustumMinRadius) ] envelopeList.append('innersphere ' + str(0.9 * distance / 2.0)) if len(coilPoints) > 1: envelopeList.append('outersphere ' + str(1.5 * distance / 2.0)) #envelopeList=['None'] # useful debug statement # generate the hairpin connection hairpinBB = self.CoilGen.generateBuildingBlock( coilLength, coil[0], coil[1], self.minDist, numCrankMoves, visualiseEnvelope=(0, 300), pointsToAvoid=pointsToAvoid, envelopeList=envelopeList) # add the hairpin to the pointsToAvoid array pointsToAvoid = np.concatenate( (pointsToAvoid, hairpinBB.blockXYZVals), 0) self.hairpinBBs.append(hairpinBB) if self.nameByBuildingBlockType: [hpin.replaceNames(self.hPinAtomName) for hpin in self.hairpinBBs] if self.dumpInterimFiles == 1: hPins = self.hairpinBBs[0].blockXYZVals for hPin in self.hairpinBBs[1:]: hPins = np.concatenate((hPins, hPin.blockXYZVals), 0) fIO.saveXYZ(hPins, self.hPinAtomName, "hPin.xyz") print "hairpins done" # assemble the components into a single final block of xyz values spidroinXYZ = self.NTerminus.blockXYZVals for betaSheet in self.betaSheetBBs: spidroinXYZ = np.concatenate((spidroinXYZ, betaSheet.blockXYZVals), 0) for hPin in self.hairpinBBs: spidroinXYZ = np.concatenate((spidroinXYZ, hPin.blockXYZVals), 0) spidroinXYZ = np.concatenate( (spidroinXYZ, self.CTerminus.blockXYZVals), 0) if self.dumpInterimFiles == 1: fIO.saveXYZ(spidroinXYZ, self.spidroinAtomName, "spidroinAsBlock.xyz") print "Spidroin Done" return spidroinXYZ
# generate the XYZVals packed in the outer cylinder # fIO.saveXYZList(WormNetworkXYZPoints, ['C'] * len(WormNetworkXYZPoints), "wormNetwork.xyz") from Projects.GeneralPolymerBrush import GeneralBlockPolymer as GBCP # generate unique polymer strands UnimerStrands = [] UnimerNum = 1 for point, director in zip(WormNetworkXYZPoints, WormNetworkXYZDirectors): print(" generating unimer ", UnimerNum, " of ", len(WormNetworkXYZPoints)) UnimerStrands += [GBCP(polymerBrushDict)] UnimerNum += 1 # transform the strands to the cylinder points xyzValsList = [] allNames = [] curStrand = 0 for directorHat, pos, strand in zip(WormNetworkXYZDirectors, WormNetworkXYZPoints, UnimerStrands): labRotation = 0.0 # rnd.uniform(0, 2 * np.pi) xyzVals = coords.transformFromBlockFrameToLabFrame( directorHat, pos, labRotation, np.array([0.0, 0.0, 1.0]), strand[0][0], strand[0]) xyzValsList += xyzVals allNames += strand[1].tolist() curStrand += 1 fIO.saveXYZList(xyzValsList, allNames, "WholeThing.xyz") print("example done")
brushDict2['Z1'] = 2 brushDict2['R1'] = 50 brushDict2['Z2'] = 1.5 * brushDict2['numMonomers'] * brushDict2[ 'bondLength'] + brushDict2['Z1'] brushDict2['R2'] = 50 polymerBrushDict = {} polymerBrushDict['backbones'] = [backboneDict1, backboneDict2 ] #, backboneDict1, backboneDict2] polymerBrushDict['brushes'] = [brushDict1, brushDict2] #, brushDict1, brushDict2] polymerBrushDict['connectors'] = [connectorDict12 ] #, connectorDict12, connectorDict12] strand = GeneralBlockPolymer(polymerBrushDict) fIO.saveXYZList(strand[0], strand[1], "Polymer.xyz") # from Library.SurfacePackSphere import SurfacePackSphereBBG as SPSBBG # SphereBBG = SPSBBG('SurfacePackSphere.txt') # # numPolymersPerSphere = 35 #430 # UnimerBaseRadius = 2 # SphereRadius = 0.15 * (backboneDict1['Z2'] + backboneDict2['Z2'] - backboneDict1['Z1'] - backboneDict2['Z1']) # phiMin = 135 # phiMax = 180 # thetaMin = -90 # thetaMax = 90 # # centerPos = np.array([0.0, 0.0, 0.0]) # # # generate the XYZVals packed in the outer cylinder
envelopeList=envelopeList, visualiseEnvelope=(0, 100)) for _ in range(numPolymersPerCylinder) ] [ strand.setBlockRefPoint(polymerStartPoint) for strand in polymer1Strands ] names = ['O'] * numA names = np.concatenate( (names, ['C'] * numB), 0 ) strandNum = 0 for strand in polymer1Strands: strand.blockAtomNames = names[:] strand.exportBBK("strand" + str(strandNum)) strandNum += 1 AllNames = [] curStrand = 0 for directorHat, pos, strand in zip(directorsHat, basePoints, polymer1Strands): strand.transformBBToLabFrame(directorHat, pos, 0.0) if curStrand==0: xyzVals = strand.blockXYZVals allNames = strand.blockAtomNames else: xyzVals = np.concatenate((xyzVals, strand.blockXYZVals), 0) allNames = np.concatenate( (allNames, strand.blockAtomNames), 0) curStrand += 1 fIO.saveXYZList(xyzVals, allNames, "polymerCylinder.xyz") print "example done"
numPointsMicelle = 160 MicelleRadius = 3.5 * brushDict['ABlock']['num'] * brushDict['ABlock']['bondLength'] minDistIntraMicelle = 0.25 * brushDict['brushBlock']['num'] * brushDict['brushBlock']['bondLength'] blockBLength = 0.8 * (brushDict['BBlock']['num'] - 1) * brushDict['BBlock']['bondLength'] minDistExtraMicelle = 2.0 * blockBLength + MicelleRadius theta1 = -90.0 theta2 = 90 phi1 = -180.0 phi2 = 90.0 numInner = 2000 InnerRadius = 300.0 minDistInner = minDistIntraMicelle numOuter = 7000 OuterRadius = InnerRadius + 4 * blockBLength minDistOuter = minDistIntraMicelle surfaceSphereFilename = "SurfacePackSphere.txt" volumeSphereFilename = "VolumePackEllipsoid.txt" micelleBrush = brushDict.copy() micelleBrush['mode'] = "PolymerRandom" vesicleBrush = brushDict.copy() vesicleBrush['mode'] = "PolymerRandom" # generate the Framboise (framboiseXYZVals, FramboiseNames) = Framboise(OuterRadius, InnerRadius, MicelleRadius, numOuter, numInner, numMicelles, numPointsMicelle, minDistInner, minDistOuter, minDistIntraMicelle, minDistExtraMicelle, theta1, theta2, phi1, phi2, surfaceSphereFilename, volumeSphereFilename, micelleBrush, vesicleBrush) fIO.saveXYZList(framboiseXYZVals, FramboiseNames, "Framboise.xyz") print "Framboise done"
] [strand.setBlockRefPoint(polymerStartPointB) for strand in TriSStrands] sTNB = np.identity(3) S1 = np.array([0.0, 0.0, 0.0]) C1 = np.array([bondLengthB, 0.0, 0.0]) S2 = np.array([ bondLengthB * (1.0 + np.cos((180.0 - 110.0) * np.pi / 180.0)), bondLengthB * np.sin((180.0 - 110.0) * np.pi / 180.0), 0.0 ]) S3 = np.array([ bondLengthB * (1.0 + np.cos((110.0 / 2.0) * np.pi / 180.0)), -1.0 * bondLengthB * np.sin((110.0 / 2.0) * np.pi / 180.0), 0.0 ]) fIO.saveXYZList([S1, C1, S2, S3], ['S', 'C', 'S', 'S'], 'S3C.xyz') S3C = XYZGenerator.generateBuildingBlock('S3C.xyz') names = ['N'] * numPEG if numHPMA > 0: names = np.concatenate((names, ['O'] * numHPMA), 0) names = np.concatenate((names, ['S', 'C', 'S', 'S']), 0) names = np.concatenate((names, ['C'] * numTriS), 0) strandNum = 0 if numHPMA > 0: for PEG, HPMA, TriS in zip(PegStrands, HPMAStrands, TriSStrands): strand, staple1 = PEG.addBuildingBlock(HPMA, 1, 0, bondLengthA, -57.0, 116.0, 180.0, 122.0, -47.0, polymerStartPointA, np.array([0.0, 0.0, 1.0]))
for i in range(numPolymersPerSphere): print(i, "unimers out of: ", numPolymersPerSphere) if i==0: innerUnimerStrands=[GeneralBlockPolymer(polymerBrushDict)] else: innerUnimerStrands.append(GeneralBlockPolymer(polymerBrushDict)) # transform the strands to the sphere points curStrand = 0 for directorHat, pos, strand in zip(outerDirectorsHat, outerSpherePoints, outerUnimerStrands): labRotation = rnd.uniform(0, 2 * np.pi) xyzVals = coords.transformFromBlockFrameToLabFrame(directorHat, pos, labRotation, np.array([0.0, 0.0, 1.0]), strand[0][0], strand[0]) if curStrand==0: xyzValsList = xyzVals allNames = strand[1] else: xyzValsList = np.concatenate((xyzValsList, xyzVals), 0) allNames = np.concatenate( (allNames, strand[1]), 0) curStrand += 1 # transform the strands to the sphere points and add to output for directorHat, pos, strand in zip(innerDirectorsHat, innerSpherePoints, innerUnimerStrands): labRotation = rnd.uniform(0, 2 * np.pi) xyzVals = coords.transformFromBlockFrameToLabFrame(directorHat, pos, labRotation, np.array([0.0, 0.0, 1.0]), strand[0][0], strand[0]) xyzValsList = np.concatenate((xyzValsList, xyzVals), 0) allNames = np.concatenate( (allNames, strand[1]), 0) curStrand += 1 fIO.saveXYZList(xyzValsList, allNames, "polymerLamellar.xyz") print("example done")
pointB = np.array([0.0, 0.0, 0.0]) print "Estimate min num residues: ", np.linalg.norm(pointA-pointB)/3.5 seedResidue.placeAtom(2, pointA) seedResidue.setBlockRefPoint(pointA) seedResidue.orientToDirector(np.array([-1.0, 1.0, 0.0])) pointsA = seedResidue.blockXYZVals[:] seedResidue.placeAtom(2, pointB) seedResidue.setBlockRefPoint(pointB) seedResidue.orientToDirector(np.array([1.0, 0.0, 1.0])) pointsB = seedResidue.blockXYZVals[:] minDist = 1.0 numCrankMoves = 0 fIO.saveXYZList([pointsA[0], pointsA[1], pointsA[2], pointsB[0], pointsB[1], pointsB[2]], ['Ca', 'Ca', 'Ca', 'O', 'O', 'O'], 'labEndPoints.xyz') envelopeList=["innersphere 4", "frustum 11.0 20.0 -5.0 2.0"] pointsToAvoid = backboneGenerator.generateBuildingBlock(10) pointsToAvoid.translateRefPointToTarget( (pointsA[2] + pointsB[2])/2.0 ) newDirector = (pointsA[2] - pointsB[2] - np.array([3.0, 0.0, 3.0])) newDirectorHat = newDirector/np.linalg.norm(newDirector) pointsToAvoid.orientToDirector(newDirectorHat) fIO.saveXYZ(pointsToAvoid.blockXYZVals, 'Li', "pointsToAvoid.xyz") # build building block and dump to file hairpinBuildingBlock = hairPinGen.generateBuildingBlock(numResidues, pointsA, pointsB, minDist, numCrankMoves, pointsToAvoid = pointsToAvoid.blockXYZVals, envelopeList=envelopeList) hairpinBuildingBlock.exportBBK(fIO.fileRootFromInfile(filename, 'txt')) print "hairpin done"
SpherePoints = SphereBB.blockXYZVals SphereBB1 = sphereBBG.generateBuildingBlock(int(2.5*numStrands), radius2, theta1, theta2, phi1, phi2, minDist2) SphereBB1.transformBBToLabFrame(director, centerPos, rotation) SphereBB1.exportBBK("sphereBasePoints1") numSpherePoints = 200 volPointBB = VolSphereBBG.generateBuildingBlock(numSpherePoints, radius3, radius3, radius3, minDist3) volPointBB.exportBBK("VolSpherePoints.xyz") peptideStrands = [ peptideBBG.generateBuildingBlock(numResidues) for _ in range(numStrands) ] directors = [ (pos - centerPos)/np.linalg.norm(pos - centerPos) for pos in SpherePoints] vesicleBBS = [ strand.transformBBToLabFrame(director, pos, 0.0) for director, pos, strand in zip(directors, SpherePoints, peptideStrands)] xyzVals = peptideStrands[0].blockXYZVals names = peptideStrands[0].blockAtomNames for strand in peptideStrands[1:]: xyzVals = np.concatenate( (xyzVals, strand.blockXYZVals), 0) names = np.concatenate( (names, strand.blockAtomNames), 0) fIO.saveXYZList(xyzVals, names, "peptideVesicle.xyz") print "example done"
[strand.setBlockRefPoint(polymerStartPoint) for strand in polymer1Strands] names = ['O'] * numA names = np.concatenate((names, ['C'] * numB), 0) strandNum = 0 for strand in polymer1Strands: strand.blockAtomNames = names[:] strand.exportBBK("strand" + str(strandNum)) strandNum += 1 directors = [(pos - centerPos) / np.linalg.norm(pos - centerPos) for pos in Polymer1SpherePoints] AllNames = [] curStrand = 0 for director, pos, strand in zip(directors, Polymer1SpherePoints, polymer1Strands): strand.transformBBToLabFrame(director, pos, 0.0) if curStrand == 0: xyzVals = strand.blockXYZVals allNames = strand.blockAtomNames else: xyzVals = np.concatenate((xyzVals, strand.blockXYZVals), 0) allNames = np.concatenate((allNames, strand.blockAtomNames), 0) curStrand += 1 fIO.saveXYZList(xyzVals, allNames, "sphere.xyz") print("example done")
def generateBuildingBlockXYZ(self): print "load spidroin coil information" spidroinCoilSpecies1Names, spidroinCoilSpecies1XYZ = fIO.loadXYZ( self.spidroinSpecies1FName) spidroinCoilSpecies2Names, spidroinCoilSpecies2XYZ = fIO.loadXYZ( self.spidroinSpecies2FName) print "Generating spidroin sites within cluster" spidroinPositionBB = self.VPESCPBBG.generateBuildingBlock( self.numPointsInCluster, self.clusterRX, self.clusterRY, self.clusterRZ, -90.0, 90.0, -180.0, 180.0, -10.0, 10.0, -10.0, 10.0, self.monomerRadius, self.terminalSeparation, 2) # compute the positions and orientations of each individual spidroin within it's cluster spidroinPositionInfo = spidroinPositionBB.blockXYZVals spidroinPositions = [ (pos + spidroinPositionInfo[2 * i + 1]) / 2.0 for i, pos in enumerate(spidroinPositionInfo[0:-1:2]) ] spidroinDirectors = [ (2.0 * float(rnd.randint(0, 1)) - 1.0) * (spidroinPositionInfo[2 * i + 1] - pos) for i, pos in enumerate(spidroinPositionInfo[0:-1:2]) ] spidroinDirectorsHat = [ director / np.linalg.norm(director) for director in spidroinDirectors ] spidroinRots = [ rnd.uniform(0.0, 360.0) for _ in range(0, self.numPointsInCluster) ] print "Generating cluster positions within the larger aggregate" clusterPositionBB = self.VPESCPBBG.generateBuildingBlock( self.numClustersInAggregate, self.aggregateRX, self.aggregateRY, self.aggregateRZ, -90.0, 90.0, -180.0, 180.0, -90.0, 90.0, -180.0, 180.0, self.clusterRY, self.clusterRX, 2) clusterPositionInfo = clusterPositionBB.blockXYZVals clusterPositions = [ (pos + clusterPositionInfo[2 * i + 1]) / 2.0 for i, pos in enumerate(clusterPositionInfo[0:-1:2]) ] clusterDirectors = [ (clusterPositionInfo[2 * i + 1] - pos) for i, pos in enumerate(clusterPositionInfo[0:-1:2]) ] clusterDirectorsHat = [ clustDir / np.linalg.norm(clustDir) for clustDir in clusterDirectors ] clusterRots = [0.0 for _ in range(0, self.numClustersInAggregate)] fIO.saveXYZList(spidroinPositions, ['Ca', 'O'] * self.numPointsInCluster, 'aggClusterPoints.xyz') print "Producing Cluster" # sety up output arrays clusterXYZ = [] clusterNames = [] spidroinNum = 0 # loop through the right number of times for the species1 data for rotation, director, position in zip( spidroinRots[0:self.numSpidroinSpecies1], spidroinDirectorsHat[0:self.numSpidroinSpecies1], spidroinPositions[0:self.numSpidroinSpecies1]): print spidroinNum if len(clusterXYZ) == 0: xyzVals = coords.transformFromBlockFrameToLabFrame( director, position, rotation, np.array([1.0, 0.0, 0.0]), np.array([0.0, 0.0, 0.0]), spidroinCoilSpecies1XYZ[:]) clusterXYZ = xyzVals[:] clusterNames = spidroinCoilSpecies1Names else: xyzVals = coords.transformFromBlockFrameToLabFrame( director, position, rotation, np.array([1.0, 0.0, 0.0]), np.array([0.0, 0.0, 0.0]), spidroinCoilSpecies1XYZ[:]) clusterXYZ = np.concatenate((clusterXYZ, xyzVals[:]), 0) clusterNames = np.concatenate( (clusterNames[:], spidroinCoilSpecies1Names), 0) spidroinNum += 1 # loop throught the species2 data and add the species two data at a slightly higher altitude. for rotation, director, position in zip( spidroinRots[self.numSpidroinSpecies1:], spidroinDirectorsHat[self.numSpidroinSpecies1:], spidroinPositions[self.numSpidroinSpecies1:]): print spidroinNum xyzVals = coords.transformFromBlockFrameToLabFrame( director, position, rotation, np.array([1.0, 0.0, 0.0]), np.array([0.0, 0.0, 0.0]), spidroinCoilSpecies2XYZ[:]) clusterXYZ = np.concatenate((clusterXYZ, xyzVals[:]), 0) clusterNames = np.concatenate( (clusterNames[:], spidroinCoilSpecies2Names), 0) spidroinNum += 1 fIO.saveXYZList(clusterXYZ, clusterNames, "cluster.xyz") print "Producing aggregate" # sety up output arrays aggregateXYZ = [] aggregateNames = [] clusterNum = 0 # loop through the right number of times for the species1 data for rotation, director, position in zip(clusterRots, clusterDirectorsHat, clusterPositions): print clusterNum if len(aggregateXYZ) == 0: xyzVals = coords.transformFromBlockFrameToLabFrame( director, position, rotation, np.array([0.0, 0.0, 1.0]), np.array([0.0, 0.0, 0.0]), clusterXYZ) aggregateXYZ = xyzVals[:] aggregateNames = clusterNames else: xyzVals = coords.transformFromBlockFrameToLabFrame( director, position, rotation, np.array([0.0, 0.0, 1.0]), np.array([0.0, 0.0, 0.0]), clusterXYZ) aggregateXYZ = np.concatenate((aggregateXYZ, xyzVals[:]), 0) aggregateNames = np.concatenate((aggregateNames, clusterNames), 0) clusterNum += 1 fIO.saveXYZList(aggregateXYZ, aggregateNames, "spidroinAggregate.xyz") self.namesTemp = aggregateNames return aggregateXYZ
R2_A = 5 alpha1A = 40 alpha2A = 60 beta1A = 165 beta2A = 185 numB = 40 bondLengthB = 1.5 minDistB = 1.0 Z1_B = 2 R1_B = 20 Z2_B = 500 R2_B = 5 alpha1B = 40 alpha2B = 50 beta1B = 145 beta2B = 155 numPolymers = 20 for i in range(numPolymers): xyzVals, names = makeBlockCopolymer(numA, numB, Z1_A, R1_A, Z2_A, R2_A, alpha1A, alpha2A, beta1A, beta2A, minDistA, bondLengthA, Z1_B, R1_B, Z2_B, R2_B, alpha1B, alpha2B, beta1B, beta2B, minDistB, bondLengthB, filename) fIO.saveXYZList(xyzVals, names, "blockCopolymer_" + str(i) + ".xyz") print("example done")
brushDict['BBlock']['num'] = 40 brushDict['BBlock']['alpha1'] = 40.0 brushDict['BBlock']['alpha2'] = 50.0 brushDict['BBlock']['beta1'] = 145.0 brushDict['BBlock']['beta2'] = 155.0 brushDict['BBlock']['minDist'] = 2.0 brushDict['BBlock']['bondLength'] = 3.0 brushDict['BBlock']['Z1'] = 2 brushDict['BBlock']['R1'] = 20 brushDict['BBlock']['Z2'] = brushDict['BBlock']['num'] * brushDict[ 'BBlock']['bondLength'] + brushDict['BBlock']['Z1'] brushDict['BBlock']['R2'] = 20 brushDict['brushBlock']['num'] = 15 brushDict['brushBlock']['alpha1'] = 40.0 brushDict['brushBlock']['alpha2'] = 50.0 brushDict['brushBlock']['beta1'] = 145.0 brushDict['brushBlock']['beta2'] = 155.0 brushDict['brushBlock']['minDist'] = 1.0 brushDict['brushBlock']['bondLength'] = 1.5 brushDict['brushBlock']['Z1'] = 0.0 brushDict['brushBlock']['R1'] = 10.0 brushDict['brushBlock']['Z2'] = brushDict['brushBlock']['num'] * brushDict[ 'brushBlock']['bondLength'] + brushDict['brushBlock']['Z1'] brushDict['brushBlock']['R2'] = 20.0 (brushDir, brushPoint, xyz, names) = PB(brushDict) fIO.saveXYZList(xyz, names, "brush.xyz") print("example done")
def generateBuildingBlock(self, numPoints, pointA, pointB, minDist, bondLength, numCrankMoves, pointsToAvoid=[], envelopeList=["None"]): self.numPoints = numPoints self.labPointA = pointA self.labPointB = pointB self.baseLength = np.linalg.norm(pointA - pointB) self.bondLength = float(bondLength) self.minDist = minDist self.blockPointA = np.array([-self.baseLength / 2, 0.0, 0.0]) self.blockPointB = np.array([self.baseLength / 2, 0.0, 0.0]) self.numCrankMoves = numCrankMoves self.allowedList = self.generateAllowedList() if self.dumpInterimFiles: fIO.saveXYZList([self.blockPointA, self.blockPointB], ['Ca', 'O'], 'blockPoints.xyz') # generate the BuildingBlock reference point earlier than usual because # we need the transformation for the pointsToAvoid input. self.blockRefPoint = self.generateBuildingBlockRefPoint() # generate the BuildingBlock director unit vector earlier than usual because # we need the transformation for the pointsToAvoid input. self.blockDirectorHat = self.generateBuildingBlockDirector() # generate the transformation information from building block to labPointA and labPointB self.labDirector, self.labRefPoint, self.labRotation = self.computeTransform( ) # convert the pointsToAvoid information from the labFrame to the block frame blockPointsToAvoid = coords.transformFromLabFrameToBlockFrame( self.labDirector, self.labRefPoint, self.labRotation, self.blockDirectorHat, self.blockRefPoint, pointsToAvoid) if self.dumpInterimFiles == 1: # these are debugging tests to make sure the transform is correct blockPointATrans = coords.transformFromLabFrameToBlockFrame( self.labDirector, self.labRefPoint, self.labRotation, self.blockDirectorHat, self.blockRefPoint, [pointA])[0] blockPointBTrans = coords.transformFromLabFrameToBlockFrame( self.labDirector, self.labRefPoint, self.labRotation, self.blockDirectorHat, self.blockRefPoint, [pointB])[0] fIO.saveXYZList([blockPointATrans, blockPointBTrans], ['Ca', 'O'], "blockPointsTransFromLab.xyz") fIO.saveXYZ(blockPointsToAvoid, 'Li', "blockPointsToAvoid.xyz") labPointsToAvoidTrans = coords.transformFromBlockFrameToLabFrame( self.labDirector, self.labRefPoint, self.labRotation, self.blockDirectorHat, self.blockRefPoint, blockPointsToAvoid) fIO.saveXYZ(labPointsToAvoidTrans, 'Be', "labPointsToAvoidTrans.xyz") # parse the envelope list now to check pointA and point B self.parseEnvelopeList(envelopeList) # store points to avoid to check pointA and point B self.pointsToAvoid = blockPointsToAvoid # check starting points are legal or it's gonna be a long wait. if not self.checkPointInBounds(self.blockPointA): print "Error Warning: PointA out of bounds" time.sleep(3) if not self.checkPointInBounds(self.blockPointB): print "Error Warning: PointB out of bounds" time.sleep(3) return BBG.generateBuildingBlock(self, numPoints, minDist, envelopeList=envelopeList, pointsToAvoid=blockPointsToAvoid)
def foldInsideEnvelope(self, xyzVals): # Perform a random crank shaft using the allowed list. If there are points intersecting reject it out of hand. # if there are less points outside the zone accept it. # if there are more points outside the zone then accept it with a probability that depends # exponentially on the difference between the current minimum number of points inside. # check which indices are outside the array curIndicesOutside = self.checkEnvelope(xyzVals) curXYZVals = xyzVals minXYZVals = xyzVals curNumIndicesOutside = len(curIndicesOutside) minNumIndicesOutside = curNumIndicesOutside minIndices = curIndicesOutside maxStepScale = 1.0 numMoves = 0 curMin = 0 threshold = 1.0 while minNumIndicesOutside > 0 and numMoves < self.maxNumFoldingMoves: # Do the crank shaft move on the current working set. # Already rejects crossovers with pointsToAvoid and selfcrossovers. # Will return the current set in those cases so no move on number of points. newXYZVals, numValidMoves = self.crankShaftMoves( curXYZVals, 1, maxStepScale) # find indices outside the envelope and count them. newIndicesOutside = self.checkEnvelope(newXYZVals) newNumIndicesOutside = len(newIndicesOutside) if numValidMoves == 1: acceptedMove = False # if a new global minimum number of indices inside the envelope then keep the move. if newNumIndicesOutside < minNumIndicesOutside: acceptedMove = True # keep a permanent log of the the new best set. minXYZVals = newXYZVals[:] minNumIndicesOutside = newNumIndicesOutside minIndices = newIndicesOutside # update the working copy curXYZVals = newXYZVals[:] curNumIndicesOutside = newNumIndicesOutside curMin += 1 if curMin < 10 and self.dumpInterimFiles == 1: fIO.saveXYZList(minXYZVals, self.blockNames, "foldMin" + str(curMin) + '.xyz') if curMin > 10 and self.dumpInterimFiles == 1 and curMin % 10 == 0: fIO.saveXYZList(minXYZVals, self.blockNames, "foldMin" + str(curMin) + '.xyz') if curMin > 100 and self.dumpInterimFiles == 1 and curMin % 100 == 0: fIO.saveXYZList(minXYZVals, self.blockNames, "foldMin" + str(curMin) + '.xyz') # if the new move means that the num indices outside has gone up above the curXYZVals then # roll the die to decide whether or not to replace the curXYZVals if newNumIndicesOutside >= minNumIndicesOutside: # roll the die. The larger the gap between newNum and minNum the smaller the threshold and the less likely we will accept the move and go back to the curXyzVals. threshold = np.exp( -(float(newNumIndicesOutside - minNumIndicesOutside)) / self.foldingTemp) if rnd.uniform(0.0, 1.0) < threshold: acceptedMove = True # update the working copy of coords but don't replace the current global minimum curXYZVals = newXYZVals curNumIndicesOutside = newNumIndicesOutside acceptedString = "rejected" if acceptedMove == True: acceptedString = "accepted" print("step:", numMoves, "out of", self.maxNumFoldingMoves, "minNumIndicesOutside:", minNumIndicesOutside, "curNumIndicesOutside:", curNumIndicesOutside, "threshold", threshold, acceptedString) numMoves += 1 if minNumIndicesOutside > 0: print( "Warning: there are points outside the envelope that were not moved inside." ) if self.dumpInterimFiles: fIO.saveXYZ(minXYZVals[minIndices], 'B', 'outsideEnvelope.xyz') return minXYZVals
namesAll.append(cp.copy(name)) startPointPolymer = np.array([0.0, 0.0, 0.0]) # generate the straight polymers for polyPos in straightPolymers.blockXYZVals: curPoly = PolyGen.generateBuildingBlock(numParticlesArm, startPointPolymer, alpha1*180/np.pi, alpha2*180/np.pi, beta1*180/np.pi, beta2*180/np.pi, atomicMinDist, bondLength) theta, phi = coords.pickRandomPointOnUnitSphere() director = coords.sphericalPolar2XYZ(np.array([1.0, theta, phi])) curPoly.transformBBToLabFrame(director, polyPos, rnd.uniform(0, 2* np.pi)) for xyzVal in curPoly.blockXYZVals: xyzValsAll.append(cp.copy(xyzVal)) for name in curPoly.blockAtomNames: namesAll.append(cp.copy(name)) # generate the helical polymers beta1Helical = 110 beta2Helical = 120 for helixPos in helicalPolymers.blockXYZVals: curPoly = PolyGen.generateBuildingBlock(numParticlesArm, startPointPolymer, alpha1 * 180/np.pi, alpha2 * 180/np.pi, beta1Helical, beta2Helical, atomicMinDist, bondLength) theta, phi = coords.pickRandomPointOnUnitSphere() director = coords.sphericalPolar2XYZ(np.array([1.0, theta, phi])) curPoly.transformBBToLabFrame(director, helixPos, rnd.uniform(0, 2* np.pi)) for xyzVal in curPoly.blockXYZVals: xyzValsAll.append(cp.copy(xyzVal)) for name in curPoly.blockAtomNames: namesAll.append(cp.copy(name)) fIO.saveXYZList(xyzValsAll, namesAll, "uncut_autodermis.xyz") print "autoDermis done"
def generateBuildingBlockXYZ(self): # The spidroin model consists of two alpha helical termini proteins which are taken from PDB files # and a spidroinHairpin Coil which is a coarse grain representation of the spidroin coil that connects # the two points at the end of the termini. # The centre of mass of the two termini are placed at +/- spidroinTerminusSeparation/2.0 on the x axis. print "CTerminus" refPosCTerm = np.array([-self.spidroinTerminusSeparation/2.0, 0.0, -2.7]) # this last 2.7 is a total hack to get pointB in the envelope self.CTerminusAll = self.CTerminusGen.generateBuildingBlock(backboneOnly = False, director = self.CTermDirectorHat, showBlockDirector=False) self.CTerminusBackbone = self.CTerminusGen.generateBuildingBlock(backboneOnly = True, director = self.CTermDirectorHat, showBlockDirector=False) self.CTerminusAll.transformBBToLabFrame(self.spidroinDirector, refPosCTerm, self.CTermRot) self.CTerminusBackbone.transformBBToLabFrame(self.spidroinDirector, refPosCTerm, self.CTermRot) self.CTerminusGen.exportPDBWithNewCoords(self.CTerminusAll.blockXYZVals, 'CTerminus_Positioned.pdb') if self.dumpInterimFiles==1: fIO.saveXYZ(self.CTerminusBackbone.blockXYZVals, self.CTerminalAtomName, "CTerminal.xyz") print "NTerminus" refPosNTerm = np.array([self.spidroinTerminusSeparation/2.0, 0.0, 0.0]) self.NTerminusAll = self.NTerminusGen.generateBuildingBlock(backboneOnly = False, director = self.NTermDirectorHat, showBlockDirector=False) self.NTerminusBackbone = self.NTerminusGen.generateBuildingBlock(backboneOnly = True, director = self.NTermDirectorHat, showBlockDirector=False) self.NTerminusAll.transformBBToLabFrame(self.spidroinDirector, refPosNTerm, self.NTermRot) self.NTerminusBackbone.transformBBToLabFrame(self.spidroinDirector, refPosNTerm, self.NTermRot) self.NTerminusGen.exportPDBWithNewCoords(self.NTerminusAll.blockXYZVals, 'NTerminus_Positioned.pdb') if self.dumpInterimFiles==1: fIO.saveXYZ(self.NTerminusBackbone.blockXYZVals, self.NTerminalAtomName, "NTerminal.xyz") print "Compute end points of spidroin coil" # Compute the coil start (A) and end (B) points. ConnectionA = self.NTerminusBackbone.getConnectionAtoms(1) # N (psi) C (phi) C (omega) N (psi) C (phi) C connection # s0 s1 s2 m2 m1 m0 # a C to N terminus connection pointsA = self.findCoilPoints(ConnectionA[0], ConnectionA[1], ConnectionA[2], self.CNbondLength, self.CNbondLength, self.CCbondLength, self.phi, self.angleC, self.omega, self.angleN, self.psi, self.angleC) pointA = pointsA[2] # find the N-terminus end of the C terminus and calculate where the coil should start ConnectionB = self.CTerminusBackbone.getConnectionAtoms(0) # C (phi) C (omega) N (psi) C (phi) C (omega) N connection # s0 s1 s2 m2 m1 m0 # an N to C terminus connection pointsB = self.findCoilPoints(ConnectionB[0], ConnectionB[1], ConnectionB[2], self.CNbondLength, self.CCbondLength, self.CNbondLength, self.omega, self.angleN, self.psi, self.angleC, self.phi, self.angleC) pointB = pointsB[2] if self.dumpInterimFiles == 1: fIO.saveXYZList([pointA, pointB], ['Ca', 'O'], "labEndPoints.xyz") print "Generating Coil" # generate a spidroin coil between each terminus. minDist = 1.0 numCrankMoves = 0 envelopeList = ['innersphere ' + str(0.9 * self.spidroinTerminusSeparation), 'frustum ' + str(self.SpidroinFrustumZ1 + 2.0) + ' ' + str(self.SpidroinFrustumMaxRadius) + ' ' + str(self.SpidroinFrustumZ2) + ' ' + str(self.SpidroinFrustumMinRadius)] visualiseEnvelopeEnvelope = 400.0 # build building block and dump to file self.spidroinHairpin = self.SpidroinCoilGen.generateBuildingBlock(self.species, pointA, pointB, minDist, numCrankMoves, envelopeList=envelopeList, visualiseEnvelope=(1000000, visualiseEnvelopeEnvelope, 'envelope_' + str(self.species) + '.xyz')) if self.dumpInterimFiles==1: fIO.saveXYZ(self.spidroinHairpin.blockXYZVals, self.spidroinHairpinAtomName, "hPinCG.xyz") print "Coarse grained hairpin done" # populate each section of the coarse grained spidroin hairpin with a peptide hairpin between the start and end points. numGUnits = self.SP2NumGUnits lenGUnit = self.SP2LenGUnitRes lenPQUnit = self.SP2LenPQUnitRes if self.species=='SP1': numGUnits = self.SP1NumGUnits lenGUnit = self.SP1LenGunitRes lenPQUnit = self.SP1LenPQunitRes radii = [minDist * self.envRadiusFactor] * numGUnits * 2 residues = [lenPQUnit, lenGUnit] * numGUnits if self.species=='SP2': residues = residues + [lenPQUnit] radii = radii + [minDist * self.envRadiusFactor] pointsA = [ xyzVal for xyzVal,name in zip(self.spidroinHairpin.blockXYZVals, self.spidroinHairpin.blockAtomNames) if name == 'N' ] pointsB = [ xyzVal for xyzVal,name in zip(self.spidroinHairpin.blockXYZVals, self.spidroinHairpin.blockAtomNames) if name == 'C' ] if self.dumpInterFiles ==1: fIO.saveXYZList(pointsA + pointsB, ['Ca'] * len(pointsA) + ['O'] * len(pointsB), "labPoints.xyz") self.COfChainsBB = CCGen.generateBuildingBlock(residues, pointsA, pointsB, radii, minDist, visualiseEnvelope=(0, 50, 'envelope.xyz')) if self.dumpInterimFiles==1: fIO.saveXYZ(self.COfChainsBB.blockXYZVals, self.spidroinHairpinAtomName, "hPin.xyz") print "detailed hairpin done" # assemble the components into a single final block of xyz values spidroinXYZ = self.NTerminusBackbone.blockXYZVals spidroinXYZ = np.concatenate( (spidroinXYZ, self.COfChainsBB.blockXYZVals), 0 ) spidroinXYZ = np.concatenate( (spidroinXYZ , self.CTerminusBackbone.blockXYZVals), 0 ) if self.dumpInterimFiles==1: fIO.saveXYZ(spidroinXYZ, self.spidroinAtomName, "spidroinAsBlock.xyz") print "Spidroin Done" return spidroinXYZ
def generateBuildingBlockXYZ(self): print "load spidroin coil information" spidroinCoilSpecies1Names, spidroinCoilSpecies1XYZ = fIO.loadXYZ( self.spidroinSpecies1FName) spidroinCoilSpecies2Names, spidroinCoilSpecies2XYZ = fIO.loadXYZ( self.spidroinSpecies2FName) print "Generating spidroin sites within cluster" spidroinPositionBB = self.SPEBBG.generateBuildingBlock( self.numPointsInCluster, self.clusterRX, self.clusterRY, self.clusterRZ, -90.0, 90.0, -180.0, 180.0, self.SpidroinRadius) # compute the positions and orientations of each individual spidroin within it's cluster spidroinPositions = spidroinPositionBB.blockXYZVals spidroinDirectors = [spidPos for spidPos in spidroinPositions] spidroinDirectorsHat = [ spidDir / np.linalg.norm(spidDir) for spidDir in spidroinDirectors ] spidroinRots = [ rnd.uniform(0, 360) for _ in range(0, self.numPointsInCluster) ] print "Generating cluster positions within the larger aggregate" clusterPositionBB = self.VPEBBG.generateBuildingBlock( self.numClustersInAggregate, self.aggregateRX, self.aggregateRY, self.aggregateRZ, -90.0, 90.0, -180.0, 180.0, (max(self.clusterRX, self.clusterRY, self.clusterRZ) + self.species2AltitudeBoost + self.TerminalExtension)) clusterPositions = clusterPositionBB.blockXYZVals clusterDirectors = [clustPos for clustPos in clusterPositions] clusterDirectorsHat = [ clustDir / np.linalg.norm(clustDir) for clustDir in clusterDirectors ] clusterRots = [ rnd.uniform(0, 360) for _ in range(0, self.numClustersInAggregate) ] fIO.saveXYZ(clusterPositions, 'Ne', 'aggClusterPoints.xyz') print "Producing Cluster" # sety up output arrays clusterXYZ = [] clusterNames = [] spidroinNum = 0 # loop through the right number of times for the species1 data for rotation, director, position in zip( spidroinRots[0:self.numSpidroinSpecies1], spidroinDirectorsHat[0:self.numSpidroinSpecies1], spidroinPositions[0:self.numSpidroinSpecies1]): print spidroinNum if len(clusterXYZ) == 0: xyzVals = coords.transformFromBlockFrameToLabFrame( director, position, rotation, np.array([0.0, 0.0, 1.0]), np.array([0.0, 0.0, 0.0]), spidroinCoilSpecies1XYZ[:]) clusterXYZ = xyzVals[:] clusterNames = spidroinCoilSpecies1Names else: xyzVals = coords.transformFromBlockFrameToLabFrame( director, position, rotation, np.array([0.0, 0.0, 1.0]), np.array([0.0, 0.0, 0.0]), spidroinCoilSpecies1XYZ[:]) clusterXYZ = np.concatenate((clusterXYZ, xyzVals[:]), 0) clusterNames = np.concatenate( (clusterNames[:], spidroinCoilSpecies1Names), 0) spidroinNum += 1 # loop throught the species2 data and add the species two data at a slightly higher altitude. for rotation, director, position in zip( spidroinRots[self.numSpidroinSpecies1:], spidroinDirectorsHat[self.numSpidroinSpecies1:], spidroinPositions[self.numSpidroinSpecies1:]): print spidroinNum xyzVals = coords.transformFromBlockFrameToLabFrame( director, position + director * self.species2AltitudeBoost, rotation, np.array([0.0, 0.0, 1.0]), np.array([0.0, 0.0, 0.0]), spidroinCoilSpecies2XYZ[:]) clusterXYZ = np.concatenate((clusterXYZ, xyzVals[:]), 0) clusterNames = np.concatenate( (clusterNames[:], spidroinCoilSpecies2Names), 0) spidroinNum += 1 fIO.saveXYZList(clusterXYZ, clusterNames, "cluster.xyz") print "Producing aggregate" # sety up output arrays aggregateXYZ = [] aggregateNames = [] clusterNum = 0 # loop through the right number of times for the species1 data for rotation, director, position in zip(clusterRots, clusterDirectorsHat, clusterPositions): print clusterNum if len(aggregateXYZ) == 0: xyzVals = coords.transformFromBlockFrameToLabFrame( director, position, rotation, np.array([0.0, 0.0, 1.0]), np.array([0.0, 0.0, 0.0]), clusterXYZ) aggregateXYZ = xyzVals[:] aggregateNames = clusterNames else: xyzVals = coords.transformFromBlockFrameToLabFrame( director, position, rotation, np.array([0.0, 0.0, 1.0]), np.array([0.0, 0.0, 0.0]), clusterXYZ) aggregateXYZ = np.concatenate((aggregateXYZ, xyzVals[:]), 0) aggregateNames = np.concatenate((aggregateNames, clusterNames), 0) clusterNum += 1 fIO.saveXYZList(aggregateXYZ, aggregateNames, "spidroinAggregate.xyz") self.namesTemp = aggregateNames return aggregateXYZ
unimerMinDist, packingFraction, minSegmentsPerWorm, coneAngleWorm, wormDirector, wormAlignmentAngularRange, numWormGenerations, minBranchAngle, wormBranchDensity, maxNumAttempts, selfAvoid=False, pointsToAvoid=[], visualiseEnvelope=(0, 20), envelopeList=["None"]) # generate the XYZVals packed in the outer cylinder fIO.saveXYZList(WormNetworkXYZPoints, ['C'] * len(WormNetworkXYZPoints), "wormNetwork.xyz") # from Projects.GeneralPolymerBrush import GeneralBlockPolymer as GBCP # # # generate unique polymer strands # for i in range(numPolymersPerCylinder): # print(i, "unimers out of: ", numPolymersPerCylinder) # if i==0: # UnimerStrands=[GeneralBlockPolymer(polymerBrushDict)] # else: # UnimerStrands.append(GeneralBlockPolymer(polymerBrushDict)) # # # transform the strands to the cylinder points # curStrand = 0 # for directorHat, pos, strand in zip(directorsHat, basePoints, UnimerStrands): # labRotation = rnd.uniform(0, 2 * np.pi)
def makeSphereAndPolymers(numA, numB, numPolymersPerSphere, FMaxRadius, FMinRadius, FZ1, FZ2, alpha1, alpha2, beta1, beta2, AtomicMinDist, bondLength, filename): SphereBBG = SPSBBG('SurfacePackSphere.txt') Polymer1Generator = RPBBG('RandomPolymer.txt') centerPos = np.array([0.0, 0.0, 0.0]) # generate the XYZVals in the packed spaced Polymer1SphereBB = SphereBBG.generateBuildingBlock(numPolymersPerSphere, FZ2, -90, 90, -180, 180, FMinRadius) Polymer1SphereBB.transformBBToLabFrame(np.array([0.0, 0.0, 1.0]), centerPos, 0.0) Polymer1SphereBB.exportBBK(filename + "_sphereBasePoints") Polymer1SpherePoints = Polymer1SphereBB.blockXYZVals envelopeList = [ 'frustum ' + str(FZ1) + ' ' + str(FMaxRadius) + ' ' + str(FZ2 - AtomicMinDist) + ' ' + str(FMinRadius) ] polymerStartPoint = np.array([0.0, 0.0, FZ2]) polymer1Strands = [ Polymer1Generator.generateBuildingBlock(numMonomersPerPolymer, polymerStartPoint, alpha1, alpha2, beta1, beta2, AtomicMinDist, bondLength, envelopeList=envelopeList, visualiseEnvelope=(0, 100)) for _ in range(numPolymersPerSphere) ] [strand.setBlockRefPoint(polymerStartPoint) for strand in polymer1Strands] names = ['O'] * numA names = np.concatenate((names, ['C'] * numB), 0) strandNum = 0 for strand in polymer1Strands: strand.blockAtomNames = names[:] strand.exportBBK(filename + "_strand" + str(strandNum)) strandNum += 1 directors = [(pos - centerPos) / np.linalg.norm(pos - centerPos) for pos in Polymer1SpherePoints] allNames = [] curStrand = 0 for director, pos, strand in zip(directors, Polymer1SpherePoints, polymer1Strands): strand.transformBBToLabFrame(director, pos, 0.0) if curStrand == 0: xyzVals = strand.blockXYZVals allNames = strand.blockAtomNames else: xyzVals = np.concatenate((xyzVals, strand.blockXYZVals), 0) allNames = np.concatenate((allNames, strand.blockAtomNames), 0) curStrand += 1 fIO.saveXYZList(xyzVals, allNames, filename + "_sphere.xyz")
nodeDist = 2 * (TubeRadius + backboneDict1['Z2'] - backboneDict1['Z1'] + backboneDict2['Z2'] - backboneDict2['Z1']) xSize = 1000 ySize = 1000 zSize = 200 MaxTubeLength = 500 MaxNumAttempts = 1000 ValidNodesPerCluster = [4] unimerBaseDist = 2 packingFraction = 0.01 # generate the XYZVals packed in the outer cylinder WormNetwork = makeWormNetwork(numNodesInit, nodeDist, xSize, ySize, zSize, TubeRadius, MaxTubeLength, MaxNumAttempts, ValidNodesPerCluster, unimerBaseDist, packingFraction) fIO.saveXYZList(WormNetwork[0], WormNetwork[2], "wormBasePointNetwork.xyz") fIO.saveXYZ([ point + director for point, director in zip(WormNetwork[0], WormNetwork[1]) ], 'O', "directorNetwork.xyz") from Projects.GeneralPolymerBrush import GeneralBlockPolymer as GBCP numUnimers = len(WormNetwork[0]) UnimerStrands = [] # generate unique polymer strands for basePos, director, index in zip(WormNetwork[0], WormNetwork[1], range(0, numUnimers)): print(index, " unimers out of: ", numUnimers) UnimerStrands += [GBCP(polymerBrushDict)]