4Misc_StartP#4Platform@9VersionCheck xHH@Rg(HHdh xHH@Rg(HHdh x HH@Rg(HHdh ^Graph*WDashSettings#  !4 4 4 4 4 4 whomeCCdMacintosh HD:Users:lingyuan:Desktop:ARecentWindows Panel0Proc0 4Misc_EndP#4XOPState_StartP#4XOPState_EndP#\!*6d TXET0RGI46Proc0Proc0#pragma TextEncoding = "UTF-8" #pragma rtGlobals=3 // Use modern global access method and strict wave access #pragma DefaultTab={3,20,4} // Set default tab width in Igor Pro 9 and later Function ButtonProc_TBGsimu(ctrlName) : ButtonControl String ctrlName Execute "TBGsimu()" End Proc TBGsimu(xx,a1,a2,theta1,theta2) variable xx = 300 variable a1 = 2.46 variable a2 = 2.46 variable theta1 = 1.05 variable theta2 = 0 prompt xx,"Length of the image (Å)" prompt a1,"Lattice constant of layer 1 (Å)" prompt a2,"Lattice constant of layer 2 (Å)" prompt theta1,"Twist angle of layer 1 (˚)" prompt theta2,"Twist angle of layer 2 (˚)" variable/G xx_TBGsimu = xx variable/G a1_TBGsimu = a1 variable/G a2_TBGsimu = a2 variable/G theta1_TBGsimu = theta1 variable/G theta2_TBGsimu = theta2 //Generate the First layer ExampleTriangularLattice(xx_TBGsimu, xx_TBGsimu, a1_TBGsimu, theta1_TBGsimu*pi/180) duplicate/o xwave layer1TBG_x duplicate/o ywave layer1TBG_y //Generate the First layer ExampleTriangularLattice(xx_TBGsimu, xx_TBGsimu, a2_TBGsimu, theta2_TBGsimu*pi/180) duplicate/o xwave layer2TBG_x duplicate/o ywave layer2TBG_y //Draw lattice display/N=TBGsimulation;modifygraph width=540,height=540 appendtograph layer1TBG_y vs layer1TBG_x appendtograph layer2TBG_y vs layer2TBG_x ModifyGraph mode=3,marker=19,msize=1.2,mrkThick=1,mirror=2,nticks=3,axThick=2 ModifyGraph rgb(layer1TBG_y)=(0,0,65535) ModifyGraph height=0,width={Plan,1,bottom,left} //Initialize Control Modula SetVariable setvar0 title="X(Å)",size={70,20},value=xx_TBGsimu,proc=SetVarProc_TBG,limits={10,inf,50} SetVariable setvar2 title="a1(Å)",size={70,20},value=a1_TBGsimu,proc=SetVarProc_TBG1,limits={1,inf,0.01} SetVariable setvar3 title="a2(Å)",size={70,20},value=a2_TBGsimu,proc=SetVarProc_TBG2,limits={1,inf,0.01} SetVariable setvar4 title="θ1(˚)",size={70,20},value=theta1_TBGsimu,proc=SetVarProc_TBG1,limits={-360,360,0.1} SetVariable setvar5 title="θ2(˚)",size={70,20},value=theta2_TBGsimu,proc=SetVarProc_TBG2,limits={-360,360,0.1} Button turnoffls3d size={45,12},valueColor=(0,0,0),fColor=(1,65535,33232),pos={370,0},proc=ButtonProc_lsturnoff3d,title="X",pos={650,0},size={20,12} end Function SetVarProc_TBG(ctrlName,varNum,varStr,varName) : SetVariableControl String ctrlName Variable varNum String varStr String varName variable/G xx_TBGsimu //= xx variable/G a1_TBGsimu //= a1 variable/G a2_TBGsimu //= a2 variable/G theta1_TBGsimu //= theta1 variable/G theta2_TBGsimu //= theta2 //Generate the First layer ExampleTriangularLattice(xx_TBGsimu, xx_TBGsimu, a1_TBGsimu, theta1_TBGsimu*pi/180) wave xwave = $"xwave" wave ywave = $"ywave" duplicate/o xwave layer1TBG_x duplicate/o ywave layer1TBG_y //Generate the Second layer ExampleTriangularLattice(xx_TBGsimu, xx_TBGsimu, a2_TBGsimu, theta2_TBGsimu*pi/180) wave xwave = $"xwave" wave ywave = $"ywave" duplicate/o xwave layer2TBG_x duplicate/o ywave layer2TBG_y End Function SetVarProc_TBG1(ctrlName,varNum,varStr,varName) : SetVariableControl String ctrlName Variable varNum String varStr String varName variable/G xx_TBGsimu //= xx variable/G a1_TBGsimu //= a1 variable/G a2_TBGsimu //= a2 variable/G theta1_TBGsimu //= theta1 variable/G theta2_TBGsimu //= theta2 //Generate the First layer ExampleTriangularLattice(xx_TBGsimu, xx_TBGsimu, a1_TBGsimu, theta1_TBGsimu*pi/180) wave xwave = $"xwave" wave ywave = $"ywave" duplicate/o xwave layer1TBG_x duplicate/o ywave layer1TBG_y End Function SetVarProc_TBG2(ctrlName,varNum,varStr,varName) : SetVariableControl String ctrlName Variable varNum String varStr String varName variable/G xx_TBGsimu //= xx variable/G a1_TBGsimu //= a1 variable/G a2_TBGsimu //= a2 variable/G theta1_TBGsimu //= theta1 variable/G theta2_TBGsimu //= theta2 //Generate the Second layer ExampleTriangularLattice(xx_TBGsimu, xx_TBGsimu, a2_TBGsimu, theta2_TBGsimu*pi/180) wave xwave = $"xwave" wave ywave = $"ywave" duplicate/o xwave layer2TBG_x duplicate/o ywave layer2TBG_y End Function ButtonProc_TTGsimu(ctrlName) : ButtonControl String ctrlName Execute "TTGsimu()" End Proc TTGsimu(xx,a1,a2,a3,theta1,theta2,theta3) variable xx = 300 variable a1 = 2.46 variable a2 = 2.46 variable a3 = 2.46 variable theta1 = 1.56 variable theta2 = 0 variable theta3 = 1.56 prompt xx,"Length of the image (Å)" prompt a1,"Lattice constant of layer 1 (Å)" prompt a2,"Lattice constant of layer 2 (Å)" prompt a3,"Lattice constant of layer 3 (Å)" prompt theta1,"Twist angle of layer 1 (˚)" prompt theta2,"Twist angle of layer 2 (˚)" prompt theta3,"Twist angle of layer 3 (˚)" variable/G xx_TTGsimu = xx variable/G a1_TTGsimu = a1 variable/G a2_TTGsimu = a2 variable/G a3_TTGsimu = a3 variable/G theta1_TTGsimu = theta1 variable/G theta2_TTGsimu = theta2 variable/G theta3_TTGsimu = theta3 //Generate the First layer ExampleTriangularLattice(xx_TTGsimu, xx_TTGsimu, a1_TTGsimu, theta1_TTGsimu*pi/180) duplicate/o xwave layer1TTG_x duplicate/o ywave layer1TTG_y //Generate the First layer ExampleTriangularLattice(xx_TTGsimu, xx_TTGsimu, a2_TTGsimu, theta2_TTGsimu*pi/180) duplicate/o xwave layer2TTG_x duplicate/o ywave layer2TTG_y //Generate the First layer ExampleTriangularLattice(xx_TTGsimu, xx_TTGsimu, a3_TTGsimu, theta3_TTGsimu*pi/180) duplicate/o xwave layer3TTG_x duplicate/o ywave layer3TTG_y //Draw lattice display/N=TTGsimulation;modifygraph width=540,height=540 appendtograph layer1TTG_y vs layer1TTG_x appendtograph layer2TTG_y vs layer2TTG_x appendtograph layer3TTG_y vs layer3TTG_x ModifyGraph mode=3,marker=19,msize=1.2,mrkThick=1,mirror=2,nticks=3,axThick=2 ModifyGraph rgb(layer2TTG_y)=(0,0,65535) ModifyGraph rgb(layer3TTG_y)=(3,52428,1) ModifyGraph height=0,width={Plan,1,bottom,left} //Initialize Control Modula SetVariable setvar0 title="X(Å)",size={70,20},value=xx_TTGsimu,proc=SetVarProc_TTG,limits={10,inf,50} SetVariable setvar2 title="a1(Å)",size={70,20},value=a1_TTGsimu,proc=SetVarProc_TTG1,limits={1,inf,0.01} SetVariable setvar3 title="a2(Å)",size={70,20},value=a2_TTGsimu,proc=SetVarProc_TTG2,limits={1,inf,0.01} SetVariable setvar32 title="a3(Å)",size={70,20},value=a3_TTGsimu,proc=SetVarProc_TTG3,limits={1,inf,0.01} SetVariable setvar4 title="θ1(˚)",size={70,20},value=theta1_TTGsimu,proc=SetVarProc_TTG1,limits={-360,360,0.1} SetVariable setvar5 title="θ2(˚)",size={70,20},value=theta2_TTGsimu,proc=SetVarProc_TTG2,limits={-360,360,0.1} SetVariable setvar52 title="θ3(˚)",size={70,20},value=theta3_TTGsimu,proc=SetVarProc_TTG3,limits={-360,360,0.1} Button turnoffls3d size={45,12},valueColor=(0,0,0),fColor=(1,65535,33232),pos={370,0},proc=ButtonProc_lsturnoff3d,title="X",pos={650,0},size={20,12} end Function SetVarProc_TTG(ctrlName,varNum,varStr,varName) : SetVariableControl String ctrlName Variable varNum String varStr String varName variable/G xx_TTGsimu //= xx variable/G a1_TTGsimu //= a1 variable/G a2_TTGsimu variable/G a3_TTGsimu variable/G theta1_TTGsimu //= theta1 variable/G theta2_TTGsimu //= theta2 variable/G theta3_TTGsimu //Generate the First layer ExampleTriangularLattice(xx_TTGsimu, xx_TTGsimu, a1_TTGsimu, theta1_TTGsimu*pi/180) wave xwave = $"xwave" wave ywave = $"ywave" duplicate/o xwave layer1TTG_x duplicate/o ywave layer1TTG_y //Generate the Second layer ExampleTriangularLattice(xx_TTGsimu, xx_TTGsimu, a2_TTGsimu, theta2_TTGsimu*pi/180) wave xwave = $"xwave" wave ywave = $"ywave" duplicate/o xwave layer2TTG_x duplicate/o ywave layer2TTG_y //Generate the Second layer ExampleTriangularLattice(xx_TTGsimu, xx_TTGsimu, a3_TTGsimu, theta3_TTGsimu*pi/180) wave xwave = $"xwave" wave ywave = $"ywave" duplicate/o xwave layer3TTG_x duplicate/o ywave layer3TTG_y End Function SetVarProc_TTG1(ctrlName,varNum,varStr,varName) : SetVariableControl String ctrlName Variable varNum String varStr String varName variable/G xx_TTGsimu //= xx variable/G a1_TTGsimu //= a1 variable/G a2_TTGsimu variable/G a3_TTGsimu variable/G theta1_TTGsimu //= theta1 variable/G theta2_TTGsimu //= theta2 variable/G theta3_TTGsimu //Generate the First layer ExampleTriangularLattice(xx_TTGsimu, xx_TTGsimu, a1_TTGsimu, theta1_TTGsimu*pi/180) wave xwave = $"xwave" wave ywave = $"ywave" duplicate/o xwave layer1TTG_x duplicate/o ywave layer1TTG_y End Function SetVarProc_TTG2(ctrlName,varNum,varStr,varName) : SetVariableControl String ctrlName Variable varNum String varStr String varName variable/G xx_TTGsimu //= xx variable/G a1_TTGsimu //= a1 variable/G a2_TTGsimu variable/G a3_TTGsimu variable/G theta1_TTGsimu //= theta1 variable/G theta2_TTGsimu //= theta2 variable/G theta3_TTGsimu //Generate the Second layer ExampleTriangularLattice(xx_TTGsimu, xx_TTGsimu, a2_TTGsimu, theta2_TTGsimu*pi/180) wave xwave = $"xwave" wave ywave = $"ywave" duplicate/o xwave layer2TTG_x duplicate/o ywave layer2TTG_y End Function SetVarProc_TTG3(ctrlName,varNum,varStr,varName) : SetVariableControl String ctrlName Variable varNum String varStr String varName variable/G xx_TTGsimu //= xx variable/G a1_TTGsimu //= a1 variable/G a2_TTGsimu variable/G a3_TTGsimu variable/G theta1_TTGsimu //= theta1 variable/G theta2_TTGsimu //= theta2 variable/G theta3_TTGsimu //Generate the Second layer ExampleTriangularLattice(xx_TTGsimu, xx_TTGsimu, a3_TTGsimu, theta3_TTGsimu*pi/180) wave xwave = $"xwave" wave ywave = $"ywave" duplicate/o xwave layer3TTG_x duplicate/o ywave layer3TTG_y End //************************************************************************** //#0 Main Function //************************************************************************** Function ExampleTriangularLattice(xx, yy, a, theta) Variable xx //= 100 // x-scale limit Variable yy// = 100 // y-scale limit Variable a //= 10 // Lattice constant Variable theta //= 0.1 // Rotation angle in radians CreateTriangularLatticeCoordinates(xx, yy, a, theta) End //************************************************************************** //************************************************************************** //#1 Core Function to output atomic positions of Honeycomb lattice //************************************************************************** Function CreateTriangularLatticeCoordinates(xx, yy, a, theta) // Input Parameters: // xx, yy: Dimensions of the wave's scale (0 to xx, 0 to yy) // a: Lattice constant // theta: In-plane rotation angle in radians // Output: // XWave, YWave: 1D waves containing x and y coordinates of all atomic centers Variable xx, yy, a, theta // Calculate center of the wave for rotation Variable centerX = xx / 2 Variable centerY = yy / 2 // Extend the range to ensure rotated lattice fills the entire wave dimensions Variable extendedX = xx + 2 * a Variable extendedY = yy + 2 * a // Calculate the number of lattice points in the extended range Variable nX = ceil(extendedX / a) Variable nY = ceil(extendedY / (sqrt(3) / 2 * a)) // Create output waves Make/O/N=(0) XWave Make/O/N=(0) YWave // Generate triangular lattice coordinates Variable i, j, x, y, xRot, yRot For (j = -1.2*nY; j <= 1.2*nY; j += 1) For (i = -1.2*nX; i <= 1.2*nX; i += 1) x = i * a + (mod(j, 2) * a / 2) // Offset for alternate rows y = j * sqrt(3) / 2 * a // Translate to origin, rotate, and translate back xRot = (x - centerX) * cos(theta) - (y - centerY) * sin(theta) + centerX yRot = (x - centerX) * sin(theta) + (y - centerY) * cos(theta) + centerY // Ensure points are within bounds If (xRot >= 0 && xRot <= xx && yRot >= 0 && yRot <= yy) // Use SetSize to dynamically add points Redimension/N=(DimSize(XWave, 0) + 1) XWave Redimension/N=(DimSize(YWave, 0) + 1) YWave XWave[DimSize(XWave, 0) - 1] = xRot YWave[DimSize(YWave, 0) - 1] = yRot EndIf EndFor EndFor // Generate second sublattice by shifting all points by a/2 along x-direction and 1/(2*sqrt(3)) along y-direction For (j = -1.2*nY; j <= 1.2*nY; j += 1) For (i = -1.2*nX; i <= 1.2*nX; i += 1) x = i * a + (mod(j, 2) * a / 2) + a / 2 // Shift by a/2 along x-direction y = j * sqrt(3) / 2 * a + (1 / (2 * sqrt(3)) * a) // Shift by 1/(2*sqrt(3)) along y-direction // Translate to origin, rotate, and translate back xRot = (x - centerX) * cos(theta) - (y - centerY) * sin(theta) + centerX yRot = (x - centerX) * sin(theta) + (y - centerY) * cos(theta) + centerY // Ensure points are within bounds If (xRot >= 0 && xRot <= xx && yRot >= 0 && yRot <= yy) Redimension/N=(DimSize(XWave, 0) + 1) XWave Redimension/N=(DimSize(YWave, 0) + 1) YWave XWave[DimSize(XWave, 0) - 1] = xRot YWave[DimSize(YWave, 0) - 1] = yRot EndIf EndFor EndFor End Function ButtonProc_lsturnoff3d(ctrlName) : ButtonControl String ctrlName string/G topo_cons string/G mat3dn_cons //string matnew = stringfromlist(0,mat3dn_cons,"_")+"_"+stringfromlist(1,mat3dn_cons,"_")+"_"+stringfromlist(2,mat3dn_cons,"_") //string win2 = "graph"+num2str(str2num(replaceString("graph",winname(0,1),""))+1) killwindow $winname(0,1) //killwindow $win2 //mat3dn_cons = matnew //** Error message, no stop but Continuing execution String msg Variable err msg=GetErrMessage(GetRTError(0),3); err=GetRTError(1) if (err != 0) //Print "Error in Demo: " + msg //Print "Continuing execution" endif End'// Platform=Macintosh, IGORVersion=9.040, architecture=Intel, systemTextEncoding="MacRoman", historyTextEncoding="UTF-8", procwinTextEncoding="UTF-8", recreationTextEncoding="UTF-8", build=56531 #pragma TextEncoding = "UTF-8" Silent 101 // use | as bitwise or -- not comment. DefaultFont "Helvetica" MoveWindow/P 5,45,705,500 String/G root:gWMSetNextTextFilesTextEncoding = "UTF-8" // Text encoding for "Proc0". Used by Igor Pro 7. OpenProc/W=(664,193,1489,944)/J=2569/V=0 "Proc0" Panel0() MoveWindow/C 46,792,1510,980 KillStrings/Z root:gWMSetNextTextFilesTextEncoding Window Panel0() : Panel PauseUpdate; Silent 1 // building window... NewPanel /W=(605,81,1004,409) SetDrawLayer UserBack SetDrawEnv fsize= 20 DrawText 99,51,"Twist Graphene Lattice" SetDrawEnv fsize= 15 DrawText 284,296,"By L. Kong" Button button0,pos={66.00,107.00},size={104.00,106.00},proc=ButtonProc_TBGsimu Button button0,title="TBG",fSize=20 Button button1,pos={236.00,108.00},size={104.00,106.00},proc=ButtonProc_TTGsimu Button button1,title="TTG",fSize=20 EndMacro #pragma TextEncoding = "UTF-8" #pragma rtGlobals=3 // Use modern global access method and strict wave access #pragma DefaultTab={3,20,4} // Set default tab width in Igor Pro 9 and later