├── .gitattributes ├── .gitignore ├── DFT-D3 ├── Makefile ├── MoveTip.py ├── copyc6.f ├── dftd3 ├── dftd3.f ├── dftd3_cellgradient ├── dftd3_gradient ├── dscf_problem ├── man.pdf ├── param └── pars.f ├── DoxyfileOrg ├── Licence.txt ├── Tutorials ├── MainzTutorial │ ├── MainzTut.py │ ├── Talk.pdf │ ├── Tutorial.pdf │ └── plot.plt ├── NaCl.dat ├── NaClforces.dat ├── tut1.py ├── tut2.py ├── tut3.py ├── tut3comp.py ├── tut4.py ├── tut5.py └── vafmcore.so ├── archive └── pyvafm.zip ├── examples ├── AmAFM.py ├── Cerium.dat.info ├── Dipole.dat.info ├── DipoleTest.py ├── FFat10.py ├── FmAfm.py ├── FmAfm_dpll.py ├── LockInTest.py ├── MgOFmAfm.py ├── NaClFmAfm.py ├── NaClTest.py ├── NaClTestTwo.py ├── PyVAFM cirucit tut.pdf ├── VDWtest.py ├── benchmark_cCore.py ├── cosalen.cube ├── example_composite.py ├── example_filter.dox ├── johntest │ ├── NaClTest.py │ ├── test_STM.py │ ├── test_STM_ConstantCurrent.py │ └── vafmcore.so ├── makeFF.py ├── quickstart.py ├── realtimer.py ├── test.py ├── test.py.org ├── test_AdvancedCantilever.py ├── test_CubeInterpolation.py ├── test_DFTVDW.py ├── test_Dipole.py ├── test_DipoleCircuit.py ├── test_FlipFlop.py ├── test_GausSmear.py ├── test_LOCPOT.py ├── test_MechAFM.py ├── test_STM.py ├── test_STM_ConstantCurrent.py ├── test_SinScan.py ├── test_VDW.py ├── test_apll.py ├── test_avg.py ├── test_cCore.py ├── test_cantilever.py ├── test_comparison.py ├── test_delay.py ├── test_derint.py ├── test_dpfd.py ├── test_events.py ├── test_filters.py ├── test_filters2.py ├── test_flipflops.py ├── test_i1Dlin.org.py ├── test_i1Dlin.py ├── test_i3Dlin.py ├── test_i4Dlin.py ├── test_interpolation.py ├── test_limiter.py ├── test_logic.py ├── test_output.py ├── test_peaker.py ├── test_perlin.py ├── test_phasor.py ├── test_pi.py ├── test_pycircuit.py ├── test_rsa.py ├── test_scanner.py ├── test_scanner2.py ├── test_scanner_image.png ├── test_wavers.py ├── tut2.py ├── tutorial_AddCircuits.py ├── tutorial_basic.py └── vafmcore.so ├── mechafm ├── Makefile ├── boron-gnr-mechafm.pdf ├── graphene.xyz ├── input.scan ├── mechafm-mpi.c ├── parameters.dat └── simple-vafm-image.py └── src ├── #Simple dipole test ├── GausSmear.py ├── cCore ├── #circuit.h# ├── circuit.h ├── circuit.h~ ├── core_Dipole.c ├── core_Dipole.h ├── core_STM.c ├── core_STM.h ├── core_TutCircuit.h ├── core_VDW.c ├── core_VDW.h ├── core_avg.c ├── core_avg.h ├── core_cantilever.c ├── core_cantilever.h ├── core_comparison.c ├── core_comparison.h ├── core_container.c ├── core_container.h ├── core_container.o-7993e806 ├── core_control.c ├── core_control.h ├── core_filters.c ├── core_filters.h ├── core_flipflops.c ├── core_flipflops.h ├── core_interpolation.c ├── core_interpolation.h ├── core_logic.c ├── core_logic.h ├── core_maths.c ├── core_maths.h ├── core_output.c ├── core_output.h ├── core_pycircuit.c ├── core_pycircuit.h ├── core_rsa.c ├── core_rsa.h ├── core_scanner.c ├── core_scanner.h ├── core_signalprocessing.c ├── core_signalprocessing.h ├── core_signals.c ├── core_signals.h ├── core_tutcirc.c ├── core_tutcirc.h ├── main.c ├── main.c~ ├── main.h ├── main.h~ ├── makefile ├── pybench.py ├── pycaller.py └── vafmcore.so ├── customs.py ├── interp3d ├── interp3d.py ├── s.py ├── tools.py ├── vafmbase.py ├── vafmcircuits.py ├── vafmcircuits_Cantilever.py ├── vafmcircuits_Comparison.py ├── vafmcircuits_DFTVDW.py ├── vafmcircuits_Dipole.py ├── vafmcircuits_Filters.py ├── vafmcircuits_FlipFlop.py ├── vafmcircuits_GaussSmear.py ├── vafmcircuits_Interpolation.py ├── vafmcircuits_Logic.py ├── vafmcircuits_MechAFM.py ├── vafmcircuits_STM.py ├── vafmcircuits_Scanner.py ├── vafmcircuits_TutCircuit.py ├── vafmcircuits_VDW.py ├── vafmcircuits_avg.py ├── vafmcircuits_control.py ├── vafmcircuits_math.py ├── vafmcircuits_output.py ├── vafmcircuits_pycirc.py ├── vafmcircuits_rsa.py ├── vafmcircuits_signal_gens.py ├── vafmcircuits_signal_processing.py └── vafmcore.so /.gitattributes: -------------------------------------------------------------------------------- 1 | DFT-D3/* linguist-vendored 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | html 2 | Work 3 | *.log 4 | *.pyc 5 | *.o 6 | *.in 7 | *.out 8 | *.sh 9 | parchg.1.0 10 | parchg.2.0 11 | parchg.1.5 12 | *.LOCPOT 13 | AM-AFM test 14 | Doxyfile 15 | DoxfileOrg 16 | doc 17 | images 18 | -------------------------------------------------------------------------------- /DFT-D3/Makefile: -------------------------------------------------------------------------------- 1 | 2 | PROG = ./dftd3 3 | 4 | #-------------------------------------------------------------------------- 5 | OSTYPE=LINUXL 6 | # source /usr/qc/lf95/csh_setup nicht vergessen (Lahey compiler) 7 | # source /usr/qc/intel/compiler70/ia32/bin/ifcvars.csh (Intel compiler) 8 | #-------------------------------------------------------------------------- 9 | 10 | OBJS1=dftd3.o copyc6.o 11 | 12 | OBJS2 = 13 | 14 | OBJS = $(OBJS1) $(OBJS2) 15 | #-------------------------------------------------------------------------- 16 | 17 | ifeq ($(OSTYPE),LINUXL) 18 | # FC = lf95 19 | # FC = ifort 20 | FC = gfortran 21 | # CC = gcc 22 | # LINKER = lf95 23 | # LINKER = ifort 24 | LINKER = gfortran 25 | PREFLAG = -E -P 26 | CCFLAGS = -O -DLINUX 27 | FFLAGS= -O 28 | # FFLAGS = -O -openmp -I$(MKLROOT)/include -mkl=parallel 29 | # LFLAGS = -openmp -I$(MKLROOT)/include -mkl=parallel 30 | # FFLAGS = -O --chk a,e,s,u 31 | # FFLAGS = -O0 -g 32 | # LFLAGS = -O0 -g 33 | endif 34 | 35 | ifeq ($(OSTYPE),LINUXI) 36 | PREOPTS = 37 | FC = ifort 38 | CC = gcc 39 | LINKER = ifort 40 | LIBS = 41 | # LIBS = -lmkl_ia32 -lmkl_lapack -lmkl_solver -lguide -lpthread -L/usr/qc/intel/mkl701/lib/32 42 | PREFLAG = -E -P 43 | CCFLAGS = -O -DLINUX 44 | FFLAGS = -w90 -O 45 | endif 46 | 47 | # diese ziele gibts: 48 | .PHONY: all 49 | .PHONY: clean 50 | # dieses ist das erste auftretende, 51 | # wird also beim aufruf von make erzeugt (default) 52 | all: $(PROG) 53 | 54 | 55 | #-------------------------------------------------------------------------- 56 | # example.f: printversion.h 57 | # example.f haengt von printversion.h ab 58 | # wenn sich also printversion.h aendert, wird example.f 59 | # (und damit auch example.o) neu gemacht. 60 | # was auch geht: 61 | 62 | #-------------------------------------------------------------------------- 63 | # implizite Regel zur Erzeugung von *.o aus *.F ausschalten 64 | %.o: %.F 65 | 66 | # aus *.F mache ein *.f 67 | %.f: %.F 68 | @echo "making $@ from $<" 69 | $(CC) $(PREFLAG) $(PREOPTS) $< -o $@ 70 | 71 | # aus *.f mache ein *.o 72 | %.o: %.f 73 | @echo "making $@ from $<" 74 | $(FC) $(FFLAGS) -c $< -o $@ 75 | 76 | # aus *.c mache ein *.o 77 | %.o: %.c 78 | @echo "making $@ from $<" 79 | $(CC) $(CCFLAGS) -c $< -o $@ 80 | 81 | # linken 82 | $(PROG): $(OBJS) 83 | $(LINKER) $(OBJS) $(LIBS) -o $(PROG) $(LFLAGS) 84 | 85 | 86 | #aufraeumen 87 | clean: 88 | rm -f *.o $(PROG) 89 | rm -f $(patsubst %.F, %.f, $(wildcard *.F)) 90 | 91 | 92 | -------------------------------------------------------------------------------- /DFT-D3/MoveTip.py: -------------------------------------------------------------------------------- 1 | filename = "AboveCe.xyz" 2 | 3 | 4 | Tipz = 5 5 | 6 | Atom = [] 7 | x = [] 8 | y = [] 9 | z = [] 10 | NumberofAtoms = 0; 11 | 12 | with open(filename,'r') as f: 13 | f.next() # skip 1 line 14 | f.next() # skip another one. 15 | for line in f: 16 | Atom.append( line.split()[0] ) 17 | x.append( float (line.split()[1] ) ) 18 | y.append( float (line.split()[2] ) ) 19 | z.append( float (line.split()[3] ) ) 20 | 21 | HighestO = 0 22 | Oi = 0; 23 | 24 | counter = 0 25 | for i in Atom: 26 | if i == "H": 27 | z[counter]+= Tipz 28 | 29 | if i == "Si": 30 | z[counter]+= Tipz 31 | 32 | if i == "O": 33 | if HighestO > z[counter]: 34 | HighestO = z[counter] 35 | Oi = counter 36 | counter += 1 37 | 38 | counter -=1 39 | 40 | 41 | z[counter]+= Tipz 42 | 43 | 44 | f = open(filename.split('.')[0] + str(Tipz*10) +"." + filename.split('.')[1] ,'w') 45 | 46 | f.write( str(len(Atom))+"\n") 47 | f.write("\n") 48 | 49 | 50 | counter = 0 51 | for i in Atom: 52 | f.write(str(i) + " " + str(x[counter]) + " " + str(y[counter]) + " " + str(z[counter]) + " \n") 53 | counter +=1 -------------------------------------------------------------------------------- /DFT-D3/dftd3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SINGROUP/PyVAFM/ac77316fe07818261e3d5c9405d8ccf9ef7508ff/DFT-D3/dftd3 -------------------------------------------------------------------------------- /DFT-D3/dftd3_cellgradient: -------------------------------------------------------------------------------- 1 | -0.21522054748319E+78 -0.12425118337139E+78 -0.24582671722700E+73 2 | 0.57839310884633E+73 -0.24851239758022E+78 0.12867348966619E+73 3 | -0.15827962905506E+73 0.56866186701846E+72 -0.62277827658740E+77 4 | -------------------------------------------------------------------------------- /DFT-D3/dscf_problem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SINGROUP/PyVAFM/ac77316fe07818261e3d5c9405d8ccf9ef7508ff/DFT-D3/dscf_problem -------------------------------------------------------------------------------- /DFT-D3/man.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SINGROUP/PyVAFM/ac77316fe07818261e3d5c9405d8ccf9ef7508ff/DFT-D3/man.pdf -------------------------------------------------------------------------------- /DFT-D3/param: -------------------------------------------------------------------------------- 1 | real*8 k1,k2,k3 2 | 3 | c global ad hoc parameters 4 | parameter (k1=16.0) 5 | parameter (k2=4./3.) 6 | 7 | c reasonable choices are between 3 and 5 8 | c this gives smoth curves with maxima around the integer values 9 | c k3=3 give for CN=0 a slightly smaller value than computed 10 | c for the free atom. This also yields to larger CN for atoms 11 | c in larger molecules but with the same chem. environment 12 | c which is physically not right 13 | c values >5 might lead to bumps in the potential 14 | parameter (k3=-4.) 15 | 16 | -------------------------------------------------------------------------------- /Tutorials/MainzTutorial/MainzTut.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import sys 3 | sys.path.append('/home/vafm/src') 4 | from vafmcircuits import Machine 5 | from customs import * 6 | import sys 7 | 8 | #Force Field units are nm and nN 9 | #Variables 10 | f0= 11 | Az= #nm 12 | Q= 13 | k= #N/m 14 | 15 | 16 | #Adding Circuits Section 1 17 | ############################################################################## 18 | machine = Machine(machine=None, name='machine', dt=1e-5) 19 | scanner = machine.AddCircuit(type='Scanner',name='scan', Process = machine, pushed=True) 20 | 21 | inter = machine.AddCircuit(type='i3Dlin',name='inter', components=1, pushed=True) 22 | inter.Configure(steps=[0.0508,0.0616625,0.005], npoints=[16,8,200]) 23 | inter.Configure(pbc=[True,True,False]) 24 | inter.Configure(ForceMultiplier=0.00166) # the values here are KJ/mol/nm. this factor brings them to nN 25 | inter.ReadData('ForceField.dat') 26 | 27 | canti = machine.AddCircuit(type='Cantilever',name='canti', startingz=Az, Q=Q, k=k, f0=f0, pushed=True) 28 | 29 | machine.AddCircuit(type="Machine",name='amp', fcut=100, assembly=aAMPD, pushed=True) 30 | 31 | 32 | ########################## 33 | #Add PI Circuit Here 34 | 35 | ########################## 36 | 37 | 38 | ########################## 39 | #Add PLL here 40 | 41 | ########################## 42 | 43 | 44 | machine.AddCircuit(type='waver',name='testwave',freq=f0,amp=1) 45 | 46 | 47 | machine.AddCircuit(type='opMul',name='exc', pushed=True) 48 | machine.AddCircuit(type='opMul',name='inv',in2=-1, pushed=True) 49 | ############################################################################## 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | #Connect Circuits Section 2 58 | ############################################################################## 59 | #pll setup 60 | 61 | 62 | 63 | machine.Connect("scan.x" , "inter.x") 64 | machine.Connect("scan.y" , "inter.y") 65 | 66 | 67 | machine.Connect("scan.z" , "canti.holderz") 68 | machine.Connect("canti.zabs" , "inter.z") 69 | 70 | 71 | #Force to cantilever 72 | machine.Connect("inter.F1" , "canti.fz") 73 | 74 | #exciter to canti 75 | machine.Connect('exc.out','canti.exciter') 76 | 77 | 78 | 79 | #machine.Connect('testwave.cos','pll.signal1') 80 | ########################## 81 | #Add Connections here 82 | 83 | 84 | 85 | ########################## 86 | 87 | ############################################################################## 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | #Setup Output Circuits Section 3 97 | ############################################################################## 98 | out1 = machine.AddCircuit(type='output',name='output',file='debug.dat', dump=1) 99 | out1.Register('global.time',"scan.x" ,'canti.zabs','amp.amp','agc.out',"pll.df") 100 | 101 | 102 | #Imaging output 103 | imager = machine.AddCircuit(type='output',name='image',file='Image.dat', dump=0) 104 | imager.Register("scan.x", "scan.y","pll.df") 105 | 106 | machine.Connect("scan.record","image.record") 107 | ############################################################################## 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | #Cantilever Movement Section 4 116 | ############################################################################## 117 | scanner.Place(x=0,y=0,z=1.5) 118 | 119 | ########################## 120 | #Pll Testing Commands 121 | ''' 122 | scanner.Place(x=0,y=0,z=1.5) 123 | machine.Wait(0.5) 124 | machine.circuits['testwave'].I['freq'].Set(f0+50) 125 | machine.Wait(0.5) 126 | machine.circuits['testwave'].I['freq'].Set(f0-300) 127 | machine.Wait(0.5) 128 | machine.circuits['testwave'].I['freq'].Set(f0+800) 129 | machine.Wait(0.5) 130 | ''' 131 | ########################## 132 | 133 | 134 | ########################## 135 | #Scripting Commands 136 | 137 | 138 | 139 | ########################## 140 | 141 | ############################################################################## -------------------------------------------------------------------------------- /Tutorials/MainzTutorial/Talk.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SINGROUP/PyVAFM/ac77316fe07818261e3d5c9405d8ccf9ef7508ff/Tutorials/MainzTutorial/Talk.pdf -------------------------------------------------------------------------------- /Tutorials/MainzTutorial/Tutorial.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SINGROUP/PyVAFM/ac77316fe07818261e3d5c9405d8ccf9ef7508ff/Tutorials/MainzTutorial/Tutorial.pdf -------------------------------------------------------------------------------- /Tutorials/MainzTutorial/plot.plt: -------------------------------------------------------------------------------- 1 | set pm3d map 2 | set palette rgbformula 34,35,36 3 | set size square 4 | sp "Image.dat" using 1:2:3 -------------------------------------------------------------------------------- /Tutorials/NaCl.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SINGROUP/PyVAFM/ac77316fe07818261e3d5c9405d8ccf9ef7508ff/Tutorials/NaCl.dat -------------------------------------------------------------------------------- /Tutorials/tut1.py: -------------------------------------------------------------------------------- 1 | from vafmbase import ChannelType 2 | from vafmcircuits import Machine 3 | import vafmcircuits 4 | 5 | #Assign the machine with a time step of 0.01 6 | machine = Machine(name='machine', dt=0.01); 7 | 8 | #Add waver and add circuit 9 | machine.AddCircuit(type='waver',name='wave', amp=1, freq=2) 10 | machine.AddCircuit(type='opAdd',name='Add') 11 | 12 | #connect a sin wave to both inputs 13 | machine.Connect("wave.sin","Add.in1") 14 | machine.Connect("wave.sin","Add.in2") 15 | 16 | #Add the output circuit and register channels 17 | out1 = machine.AddCircuit(type='output',name='output',file='tut1.dat', dump=1) 18 | out1.Register('global.time', 'wave.sin', 'Add.out') 19 | 20 | #ask the machine to wait for 5 seconds 21 | machine.Wait(5) -------------------------------------------------------------------------------- /Tutorials/tut2.py: -------------------------------------------------------------------------------- 1 | from vafmbase import ChannelType 2 | from vafmcircuits import Machine 3 | import vafmcircuits 4 | 5 | 6 | machine = Machine(machine=None, name='machine', dt=0.01) 7 | scan = machine.AddCircuit(type='Scanner',name='scann') 8 | inter = machine.AddCircuit(type='i3Dlin',name='inter', components=3) 9 | 10 | inter.Configure(steps=[0.705,0.705,0.1], npoints=[8,8,201]) 11 | inter.Configure(pbc=[True,True,False]) 12 | inter.ReadData('NaClforces.dat') 13 | 14 | machine.Connect("scann.x" , "inter.x") 15 | machine.Connect("scann.y" , "inter.y") 16 | machine.Connect("scann.z" , "inter.z") 17 | 18 | 19 | #image output 20 | imager = machine.AddCircuit(type='output',name='image',file='tut2.dat', dump=0) 21 | imager.Register("scann.x", "scann.y", 'inter.F3') 22 | 23 | machine.Connect("scann.record", "image.record") 24 | 25 | scan.Place(x=0, y=0, z=4) 26 | #this will print an empty line after each scanline 27 | scan.Recorder = imager 28 | scan.BlankLines = True 29 | #not necessary, but it makes it easier for gnuplot 30 | 31 | #resolution of the image [# points per line, # lines] 32 | scan.Resolution = [64,64] 33 | scan.ImageArea(11.68,11.68) 34 | 35 | #scan 36 | scan.ScanArea() -------------------------------------------------------------------------------- /Tutorials/tut3.py: -------------------------------------------------------------------------------- 1 | from vafmbase import ChannelType 2 | from vafmcircuits import Machine 3 | from tut3comp import * 4 | import vafmcircuits 5 | 6 | 7 | 8 | machine = Machine(name='machine', dt=0.01); 9 | 10 | machine.AddCircuit(type='waver',name='osc', amp=1, freq=1) 11 | 12 | machine.AddCircuit(type='Machine', name='compo1', assembly=ADC) 13 | 14 | out1 = machine.AddCircuit(type='output',name='output',file='tut3.dat', dump=1) 15 | out1.Register('global.time', 'osc.sin', 'compo1.out') 16 | 17 | machine.Connect("osc.sin","compo1.signal1") 18 | machine.Connect("osc.sin","compo1.signal2") 19 | 20 | machine.Wait(5) -------------------------------------------------------------------------------- /Tutorials/tut3comp.py: -------------------------------------------------------------------------------- 1 | from vafmbase import ChannelType 2 | from vafmcircuits import Machine 3 | import vafmcircuits 4 | 5 | 6 | def ADC(compo,**keys): 7 | 8 | compo.AddInput("signal1") 9 | compo.AddInput("signal2") 10 | compo.AddOutput("out") 11 | compo.AddCircuit(type='opAdd',name='adder') 12 | compo.Connect("global.signal1","adder.in1") 13 | compo.Connect("global.signal2","adder.in2") 14 | compo.Connect("adder.out","global.out") 15 | 16 | print "ADC assembled!" 17 | -------------------------------------------------------------------------------- /Tutorials/tut4.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | from customs import * 4 | 5 | 6 | machine = Machine(machine=None, name='machine', dt=5e-8) 7 | f0=23065 8 | #Angstrom 9 | Az=0.387 10 | 11 | scanner = machine.AddCircuit(type='Scanner',name='scan', Process = machine, pushed=True) 12 | 13 | canti = machine.AddCircuit(type='Cantilever',name='canti', Q=42497, k=112.32, f0=f0, startingz=Az, pushed=True) 14 | 15 | machine.AddCircuit(type="Machine",name='amp', fcut=500, assembly=aAMPD, pushed=True) 16 | 17 | machine.AddCircuit(type="PI",name='agc', Ki=2.1, Kp=0.1, set=Az, pushed=True) 18 | machine.AddCircuit(type="limiter",name='agclim', min=0,max=10, pushed=True) 19 | 20 | machine.AddCircuit(type="Machine",name='pll', assembly=dPFD, gain=1000.0, fcut=500, KI=3,KP=0.5, f0=f0 , pushed=True) 21 | 22 | machine.AddCircuit(type='opMul',name='pllinv',in2=-1, pushed=True) 23 | machine.AddCircuit(type='opMul',name='exc', pushed=True) 24 | 25 | 26 | machine.AddCircuit(type='VDWtorn', name='Dimer',A1=-0.0166279, A2=0.22753, A3=-1819.29, A4=27055.6, A5=-106878., A6=31.8093, tipoffset=0, pushed=True) 27 | 28 | 29 | 30 | 31 | machine.Connect("scan.z" , "canti.holderz") 32 | machine.Connect("canti.zabs" , "Dimer.ztip") 33 | machine.Connect("Dimer.fz" , "canti.fz") 34 | 35 | 36 | 37 | machine.Connect('canti.ztip','amp.signal') 38 | machine.Connect('amp.amp','agc.signal') 39 | machine.Connect('amp.norm','pll.ref') 40 | machine.Connect('pll.cos','pll.vco') 41 | 42 | machine.Connect('agc.out','agclim.signal') 43 | machine.Connect('agclim.out','exc.in1') 44 | machine.Connect('pll.sin','pllinv.in1') 45 | machine.Connect('pllinv.out','exc.in2') 46 | 47 | machine.Connect('exc.out','canti.exciter') 48 | 49 | 50 | out3 = machine.AddCircuit(type='output',name='output3',file='tut4.dat', dump=0) 51 | out3.Register("scan.z", "pll.df") 52 | out3.Stop() 53 | 54 | 55 | machine.Connect("scan.record","output3.record") 56 | 57 | 58 | scanner.Place(x=0,y=0,z=15) 59 | scanner.Move(x=0,y=0,z=-1) 60 | machine.Wait(1) 61 | 62 | out3.Start() 63 | scanner.MoveRecord(x=0,y=0,z=-9.5,v=1,points=200) 64 | 65 | -------------------------------------------------------------------------------- /Tutorials/tut5.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | from customs import * 4 | 5 | 6 | machine = Machine(machine=None, name='machine', dt=5.0e-8) 7 | 8 | 9 | canti = machine.AddCircuit(type='Cantilever',name='canti', startingz=0.5,Q=10000, k=167.0, f0=150000, pushed=True) 10 | 11 | 12 | machine.AddCircuit(type="Machine",name='amp', fcut=[10000], assembly=aAMPD, pushed=True) 13 | 14 | machine.AddCircuit(type='PI', name='agc', Kp=1.1, Ki=800, set=1, pushed=True) 15 | machine.AddCircuit(type="limiter",name='agclim', min=-100000,max=1000000, pushed=True) 16 | 17 | machine.AddCircuit(type="Machine",name='pll', fcut=1000, assembly=aPLL, filters=[10000,5000,2000], gain=600.0, f0=150000, Kp=0.5, Ki=700, pushed=True) 18 | 19 | machine.AddCircuit(type='opMul',name='pllinv',in2=-1, pushed=True) 20 | machine.AddCircuit(type='opMul',name='exc', pushed=True) 21 | 22 | scanner = machine.AddCircuit(type='Scanner',name='scan', Process = machine, pushed=True) 23 | 24 | 25 | inter = machine.AddCircuit(type='i3Dlin',name='inter', components=3, pushed=True) 26 | inter.Configure(steps=[0.705,0.705,0.1], npoints=[8,8,201]) 27 | inter.Configure(pbc=[True,True,False]) 28 | inter.Configure(ForceMultiplier=1e10) 29 | inter.ReadData('NaClforces.dat') 30 | 31 | 32 | 33 | 34 | 35 | #Outputs 36 | out1 = machine.AddCircuit(type='output',name='output',file='testafm.out', dump=2) 37 | out1.Register('global.time', 'canti.zabs','amp.amp','pll.cos','pll.sin','exc.in2') 38 | out1.Stop() 39 | 40 | out2 = machine.AddCircuit(type='output',name='output2',file='testafm2.out', dump=10000) 41 | out2.Register('global.time', 'canti.ztip','agc.out','pll.df',"canti.fz",'amp.amp') 42 | out2.Stop() 43 | 44 | #Imaging output 45 | imager = machine.AddCircuit(type='output',name='image',file='NaCl.dat', dump=0) 46 | imager.Register("scan.x","scan.y","pll.df") 47 | 48 | 49 | #feed x and y to interpolation 50 | machine.Connect("scan.x" , "inter.x") 51 | machine.Connect("scan.y" , "inter.y") 52 | machine.Connect("scan.z" , "canti.holderz") 53 | machine.Connect("canti.zabs" , "inter.z") 54 | 55 | #Force 56 | machine.Connect("inter.F3" , "canti.fz") 57 | 58 | machine.Connect('canti.ztip','amp.signal') 59 | machine.Connect('amp.amp','agc.signal') 60 | machine.Connect('amp.norm','pll.signal1') 61 | machine.Connect('pll.cos','pll.signal2') 62 | 63 | machine.Connect('agc.out','agclim.signal') 64 | machine.Connect('agclim.out','exc.in1') 65 | machine.Connect('pll.cos','pllinv.in1') 66 | machine.Connect('pllinv.out','exc.in2') 67 | 68 | machine.Connect('exc.out','canti.exciter') 69 | 70 | machine.Connect("scan.record","image.record") 71 | 72 | 73 | 74 | scanner.Place(x=0,y=0,z=15) 75 | machine.Wait(0.1) 76 | 77 | scanner.Move(x=0,y=0,z=-11) 78 | machine.Wait(0.1) 79 | 80 | scanner.Recorder = imager 81 | scanner.BlankLines = True 82 | #resolution of the image [# points per line, # lines] 83 | scanner.Resolution = [64,64] 84 | scanner.ImageArea(12,12) 85 | #scan 86 | scanner.ScanArea() 87 | 88 | -------------------------------------------------------------------------------- /Tutorials/vafmcore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SINGROUP/PyVAFM/ac77316fe07818261e3d5c9405d8ccf9ef7508ff/Tutorials/vafmcore.so -------------------------------------------------------------------------------- /archive/pyvafm.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SINGROUP/PyVAFM/ac77316fe07818261e3d5c9405d8ccf9ef7508ff/archive/pyvafm.zip -------------------------------------------------------------------------------- /examples/AmAFM.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | from customs import * 4 | #TEST 5 | 6 | def main(): 7 | 8 | machine = Machine(machine=None, name='machine', dt=5.0e-8) 9 | # canti = machine.AddCircuit(type='Cantilever',name='canti', 10 | # Q=20000, k=26.5, f0=150000, startingz=1, pushed=True) 11 | 12 | 13 | canti = machine.AddCircuit(type='Cantilever',name='canti', startingz=0.5, 14 | Q=10000, k=167.0, f0=150000, pushed=True) 15 | 16 | machine.AddCircuit(type='waver',name='wave',freq=150000-100,amp=1) 17 | 18 | machine.AddCircuit(type="Machine",name='amp', fcut=10000, assembly=aAMPD, 19 | pushed=True) 20 | 21 | # machine.AddCircuit(type="PI",name='agc', Ki=2.1, Kp=0.1, set=0.1, pushed=True) 22 | machine.AddCircuit(type='PI', name='agc', Kp=1.1, Ki=800, set=1, pushed=True) 23 | machine.AddCircuit(type="limiter",name='agclim', min=0,max=10, pushed=True) 24 | 25 | machine.AddCircuit(type="Machine",name='pll', fcut=1000, assembly=aPLL, 26 | filters=[10000,5000,2000], gain=600.0, f0=150000, Kp=0.5, Ki=700, 27 | pushed=True) 28 | 29 | machine.AddCircuit(type='opMul',name='pllinv',in2=-1, pushed=True) 30 | machine.AddCircuit(type='opMul',name='exc', pushed=True) 31 | 32 | scanner = machine.AddCircuit(type='Scanner',name='scan', Process = machine, pushed=True) 33 | 34 | 35 | inter = machine.AddCircuit(type='i3Dlin',name='inter', components=3, pushed=True) 36 | inter.Configure(steps=[0.705,0.705,0.1], npoints=[8,8,171]) 37 | inter.Configure(pbc=[True,True,False]) 38 | inter.Configure(ForceMultiplier=1e10) 39 | inter.ReadData('NaClforces.dat') 40 | 41 | 42 | 43 | 44 | 45 | #Outputs 46 | out1 = machine.AddCircuit(type='output',name='output',file='testafm.out', dump=10000) 47 | out1.Register('global.time', 'canti.zabs','amp.norm','exc.in2') 48 | #out1.Register('global.time', 'wave.cos','pll.cos','pll.sin','exc.in2') 49 | out1.Stop() 50 | 51 | out2 = machine.AddCircuit(type='output',name='output2',file='testafm2.out', dump=1000) 52 | out2.Register('global.time', 'canti.ztip','agc.out',"canti.fz","amp.amp") 53 | out2.Stop() 54 | 55 | #Imaging output 56 | imager = machine.AddCircuit(type='output',name='image',file='NaCl.dat', dump=0) 57 | imager.Register("scan.x","scan.y",'agc.out') 58 | 59 | 60 | #feed x and y to interpolation 61 | machine.Connect("scan.x" , "inter.x") 62 | machine.Connect("scan.y" , "inter.y") 63 | machine.Connect("scan.z" , "canti.holderz") 64 | machine.Connect("canti.zabs" , "inter.z") 65 | 66 | #Force 67 | machine.Connect("inter.F3" , "canti.fz") 68 | 69 | machine.Connect('canti.ztip','amp.signal') 70 | machine.Connect('amp.amp','agc.signal') 71 | #machine.Connect('amp.norm','pll.signal1') 72 | #machine.Connect('wave.cos','pll.signal1') 73 | #machine.Connect('pll.cos','pll.signal2') 74 | 75 | machine.Connect('agc.out','agclim.signal') 76 | machine.Connect('agclim.out','exc.in1') 77 | # machine.Connect('pll.cos','pllinv.in1') 78 | # machine.Connect('pllinv.out','exc.in2') 79 | machine.Connect('wave.sin','exc.in2') 80 | 81 | 82 | 83 | machine.Connect('exc.out','canti.exciter') 84 | 85 | machine.Connect("scan.record","image.record") 86 | 87 | 88 | 89 | 90 | 91 | ''' 92 | machine.Wait(0.01) 93 | out1.Start() 94 | machine.Wait(0.001) 95 | out1.Stop() 96 | machine.Wait(0.05) 97 | out1.Start() 98 | machine.Wait(0.001) 99 | ''' 100 | #plot testafm.out 1:3 (canti) 1:4 (pll reference) 1:6 (the exciter) 101 | #u should see 3 distinct waves, canti peaks are in the middle between the other 2 102 | 103 | scanner.Place(x=0,y=0,z=15) 104 | machine.Wait(0.5) 105 | 106 | scanner.Move(x=0,y=0,z=-11) 107 | machine.Wait(1) 108 | 109 | 110 | 111 | 112 | #machine.SetInput(channel="output.record", value=1) 113 | scanner.Recorder = imager 114 | scanner.BlankLines = True 115 | #resolution of the image [# points per line, # lines] 116 | scanner.Resolution = [20,1] 117 | scanner.ImageArea(11.28,11.28) 118 | #scan 119 | scanner.ScanArea() 120 | 121 | 122 | if __name__ == '__main__': 123 | main() 124 | 125 | -------------------------------------------------------------------------------- /examples/Cerium.dat.info: -------------------------------------------------------------------------------- 1 | Stepsze in x,y,z: 0.072049037037,0.0720490369539,0.0741075825003 2 | Number Of points in x,y,z : 215,215,285 3 | Size in x,y,z : 15.562592,15.562591982,31.1251846501 4 | 5 | Lattice Vector x : 15.562592,0.0,0.0 6 | Lattice Vector y : -7.781296,13.4776,0.0 7 | Lattice Vector z : 15.562592,-8.985067,25.413607 8 | -------------------------------------------------------------------------------- /examples/Dipole.dat.info: -------------------------------------------------------------------------------- 1 | Stepsze in x,y,z: 0.072049037037,0.0720490369539,0.0741075825003 2 | Number Of points in x,y,z : 215,215,285 3 | Size in x,y,z : 15.562592,15.562591982,31.1251846501 4 | -------------------------------------------------------------------------------- /examples/DipoleTest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | from customs_pll import * 4 | 5 | 6 | machine = Machine(machine=None, name='machine', dt=5.0e-8) 7 | 8 | 9 | canti = machine.AddCircuit(type='Cantilever',name='canti', startingz=2,Q=10000, k=167.0, f0=150000, pushed=True) 10 | 11 | 12 | machine.AddCircuit(type="Machine",name='amp', fcut=10000, assembly=aAMPD, pushed=True) 13 | 14 | machine.AddCircuit(type='PI', name='agc', Kp=1.1, Ki=800, set=2, pushed=True) 15 | machine.AddCircuit(type="limiter",name='agclim', min=-100000,max=1000000, pushed=True) 16 | 17 | machine.AddCircuit(type="Machine",name='pll', fcut=1000, assembly=aPLL, filters=[10000,5000,2000], gain=600.0, f0=150000, Kp=0.5, Ki=700, pushed=True) 18 | 19 | machine.AddCircuit(type='opMul',name='pllinv',in2=-1, pushed=True) 20 | machine.AddCircuit(type='opMul',name='exc', pushed=True) 21 | 22 | scanner = machine.AddCircuit(type='Scanner',name='scan', Process = machine, pushed=True) 23 | 24 | inter = machine.AddCircuit(type='i3Dlin',name='inter', components=1) 25 | inter.Configure(steps=[0.072049037037, 0.0748755555556, 0.075635735119], npoints=[216,180,335]) 26 | inter.Configure(pbc=[True,True,False]) 27 | inter.ReadData('testCeo2.dat') 28 | 29 | 30 | 31 | 32 | 33 | 34 | #Outputs 35 | out1 = machine.AddCircuit(type='output',name='output',file='testafm.out', dump=2) 36 | out1.Register('global.time', 'canti.zabs','amp.norm','pll.cos','pll.sin','exc.in2') 37 | out1.Stop() 38 | 39 | out2 = machine.AddCircuit(type='output',name='output2',file='testafm2.out', dump=1000) 40 | out2.Register('global.time', 'canti.ztip','agc.out','pll.df',"canti.fz") 41 | out2.Stop() 42 | 43 | #Imaging output 44 | imager = machine.AddCircuit(type='output',name='image',file='FMDipole.dat', dump=0) 45 | imager.Register("scan.x","scan.y","pll.df") 46 | 47 | 48 | #feed x and y to interpolation 49 | machine.Connect("scan.x" , "inter.x") 50 | machine.Connect("scan.y" , "inter.y") 51 | machine.Connect("scan.z" , "canti.holderz") 52 | machine.Connect("canti.zabs" , "inter.z") 53 | 54 | 55 | #Force 56 | machine.Connect("inter.F1" , "canti.fz") 57 | 58 | machine.Connect('canti.ztip','amp.signal') 59 | machine.Connect('amp.amp','agc.signal') 60 | machine.Connect('amp.norm','pll.signal1') 61 | machine.Connect('pll.cos','pll.signal2') 62 | 63 | machine.Connect('agc.out','agclim.signal') 64 | machine.Connect('agclim.out','exc.in1') 65 | machine.Connect('pll.cos','pllinv.in1') 66 | machine.Connect('pllinv.out','exc.in2') 67 | 68 | machine.Connect('exc.out','canti.exciter') 69 | 70 | machine.Connect("scan.record","image.record") 71 | 72 | 73 | 74 | 75 | scanner.Place(x=0,y=0,z=18) 76 | machine.Wait(0.1) 77 | 78 | 79 | scanner.Move(x=0,y=0,z=-2) 80 | machine.Wait(0.1) 81 | 82 | scanner.Recorder = imager 83 | scanner.BlankLines = True 84 | #resolution of the image [# points per line, # lines] 85 | scanner.Resolution = [128,1] 86 | scanner.ImageArea(16,16) 87 | #scan 88 | scanner.ScanArea() 89 | -------------------------------------------------------------------------------- /examples/FFat10.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | 4 | machine = Machine(machine=None, name='machine', dt=0.01) 5 | 6 | #machine.AddCircuit(type='CoordTransform',name='CT', LatticeVectorX=[15.562592,0.0,0.0], LatticeVectorY=[-7.781296,13.4776,0.0], LatticeVectorZ=[15.562592,-8.985067,25.413607] ,pushed=True) 7 | 8 | 9 | scan = machine.AddCircuit(type='Scanner',name='scann') 10 | #inter = machine.AddCircuit(type='i3Dlin',name='inter', components=1) 11 | 12 | ''' 13 | inter.Configure(steps=[0.072049037037, 0.0748755555556, 0.075635735119], npoints=[216,180,332]) 14 | inter.Configure(pbc=[True,True,False]) 15 | inter.ReadData('TestCeo2.dat') 16 | ''' 17 | 18 | inter = machine.AddCircuit(type='i3Dlin',name='inter', components=3, pushed=True) 19 | inter.Configure(steps=[0.705,0.705,0.1], npoints=[8,8,201]) 20 | inter.Configure(pbc=[True,True,False]) 21 | inter.Configure(ForceMultiplier=1e10) 22 | inter.ReadData('NaClforces.dat') 23 | 24 | 25 | machine.Connect("scann.x" , "inter.x") 26 | machine.Connect("scann.y" , "inter.y") 27 | machine.Connect("scann.z" , "inter.z") 28 | 29 | #machine.Connect("CT.xprime","inter.x") 30 | #machine.Connect("CT.yprime","inter.y") 31 | #machine.Connect("CT.zprime","inter.z") 32 | 33 | 34 | 35 | 36 | dist = 0 37 | 38 | 39 | #image output 40 | imager = machine.AddCircuit(type='output',name='image',file='test.dat', dump=0) 41 | imager.Register("scann.x", "scann.y", 'inter.F3') 42 | 43 | machine.Connect("scann.record", "image.record") 44 | 45 | #machine.Wait(0.01) 46 | 47 | #this will print an empty line after each scanline 48 | scan.Recorder = imager 49 | scan.BlankLines = True 50 | scan.Resolution = [64,64] 51 | scan.ImageArea(12,12) 52 | 53 | scan.Place(x=0, y=0, z=10) 54 | 55 | #scan 56 | scan.ScanArea() 57 | dist += 1 58 | 59 | -------------------------------------------------------------------------------- /examples/FmAfm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | from customs import * 4 | 5 | 6 | def main(): 7 | 8 | machine = Machine(machine=None, name='machine', dt=5.0e-8) 9 | canti = machine.AddCircuit(type='Cantilever',name='canti', 10 | Q=20000, k=26.4, f0=150000, startingz=1, pushed=True) 11 | 12 | #machine.AddCircuit(type='waver',name='wave',freq=150000,amp=1) 13 | 14 | machine.AddCircuit(type="Machine",name='amp', fcut=10000, assembly=aAMPD, 15 | pushed=True) 16 | 17 | machine.AddCircuit(type="PI",name='agc', Ki=2.1, Kp=0.1, set=10, pushed=True) 18 | machine.AddCircuit(type="limiter",name='agclim', min=0,max=10, pushed=True) 19 | 20 | machine.AddCircuit(type="Machine",name='pll', fcut=1000, assembly=aPLL, 21 | filters=[10000,5000,2000], gain=600.0, f0=150000, Kp=0.5, Ki=700, 22 | pushed=True) 23 | 24 | machine.AddCircuit(type='opMul',name='pllinv',in2=-1, pushed=True) 25 | machine.AddCircuit(type='opMul',name='exc', pushed=True) 26 | 27 | machine.Connect('canti.ztip','amp.signal') 28 | machine.Connect('amp.amp','agc.signal') 29 | machine.Connect('amp.norm','pll.signal1') 30 | #machine.Connect('wave.cos','pll.signal1') 31 | machine.Connect('pll.cos','pll.signal2') 32 | 33 | machine.Connect('agc.out','agclim.signal') 34 | machine.Connect('agclim.out','exc.in1') 35 | machine.Connect('pll.cos','pllinv.in1') 36 | machine.Connect('pllinv.out','exc.in2') 37 | 38 | machine.Connect('exc.out','canti.exciter') 39 | 40 | #Outputs 41 | out1 = machine.AddCircuit(type='output',name='output',file='testafm.out', dump=2) 42 | out1.Register('global.time', 'canti.zabs','amp.norm','pll.cos','pll.sin','exc.in2') 43 | #out1.Register('global.time', 'wave.cos','pll.cos','pll.sin','exc.in2') 44 | out1.Stop() 45 | 46 | out2 = machine.AddCircuit(type='output',name='output2',file='testafm2.out', dump=100) 47 | out2.Register('global.time', 'amp.amp','agc.out','pll.df') 48 | 49 | machine.Wait(0.01) 50 | out1.Start() 51 | machine.Wait(0.001) 52 | out1.Stop() 53 | machine.Wait(0.05) 54 | out1.Start() 55 | machine.Wait(0.001) 56 | 57 | #plot testafm.out 1:3 (canti) 1:4 (pll reference) 1:6 (the exciter) 58 | #u should see 3 distinct waves, canti peaks are in the middle between the other 2 59 | 60 | if __name__ == '__main__': 61 | main() 62 | 63 | 64 | -------------------------------------------------------------------------------- /examples/FmAfm_dpll.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | from customs import * 4 | 5 | 6 | def main(): 7 | 8 | machine = Machine(machine=None, name='machine', dt=5.0e-8) 9 | canti = machine.AddCircuit(type='Cantilever',name='canti', 10 | Q=20000, k=26.4, f0=150000, startingz=1, pushed=True) 11 | 12 | #machine.AddCircuit(type='waver',name='wave',freq=150000,amp=1) 13 | 14 | machine.AddCircuit(type="Machine",name='amp', fcut=10000, assembly=aAMPD, 15 | pushed=True) 16 | 17 | machine.AddCircuit(type="PI",name='agc', Ki=2.1, Kp=0.1, set=10, pushed=True) 18 | machine.AddCircuit(type="limiter",name='agclim', min=0,max=10, pushed=True) 19 | 20 | machine.AddCircuit(type="Machine",name='pll', fcut=1000, assembly=dPFD, 21 | gain=1000.0, f0=150000, KP=1.0, KI=100, pushed=True) 22 | 23 | machine.AddCircuit(type='opMul',name='pllinv',in2=-1, pushed=True) 24 | machine.AddCircuit(type='opMul',name='exc', pushed=True) 25 | 26 | machine.AddCircuit(type='phasor',name='pew', pushed=True) 27 | 28 | machine.Connect('canti.ztip','amp.signal') 29 | machine.Connect('amp.amp','agc.signal') 30 | machine.Connect('amp.norm','pll.ref', 'pew.in1') 31 | #machine.Connect('wave.cos','pll.ref') 32 | machine.Connect('pll.cos','pll.vco','pew.in2') 33 | 34 | machine.Connect('agc.out','agclim.signal') 35 | machine.Connect('agclim.out','exc.in1') 36 | machine.Connect('pll.sin','pllinv.in1') 37 | machine.Connect('pllinv.out','exc.in2') 38 | 39 | machine.Connect('exc.out','canti.exciter') 40 | 41 | #Outputs 42 | out1 = machine.AddCircuit(type='output',name='output',file='testafm.out', dump=2) 43 | out1.Register('global.time', 'canti.zabs','amp.norm','pll.cos','pll.sin','exc.in2','pll.dbg') 44 | #out1.Register('global.time', 'wave.cos','pll.cos','pll.sin','exc.in2') 45 | out1.Stop() 46 | 47 | out2 = machine.AddCircuit(type='output',name='output2',file='testafm2.out', dump=100) 48 | out2.Register('global.time', 'amp.amp','agc.out','pll.df','pew.delay') 49 | 50 | machine.Wait(0.01) 51 | out1.Start() 52 | machine.Wait(0.001) 53 | out1.Stop() 54 | 55 | machine.Wait(0.05) 56 | out1.Start() 57 | machine.Wait(0.001) 58 | 59 | #plot testafm.out 1:3 (canti) 1:4 (pll reference) 1:6 (the exciter) 60 | #u should see 3 distinct waves, canti peaks are in the middle between the other 2 61 | 62 | if __name__ == '__main__': 63 | main() 64 | 65 | -------------------------------------------------------------------------------- /examples/LockInTest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | from customs import * 4 | import math 5 | 6 | machine = Machine(machine=None, name='Machine', dt=1e-8) 7 | 8 | f0=350000 9 | #nm 10 | Az=0.3 11 | Q=4 12 | #N/m 13 | k=4 14 | 15 | machine.AddCircuit(type="Machine",name='LockInAmp', intTime=1.0/f0 * 1000, CentFreq=f0, Gain=2 ,assembly=LockInAmp,OutAmp=1, pushed=True) 16 | #canti = machine.AddCircuit(type='Cantilever',name='canti', startingz=Az, Q=Q, k=k, f0=f0, pushed=True) 17 | machine.AddCircuit(type='minmax', name='amp' , CheckTime = 1e-5) 18 | 19 | machine.AddCircuit(type='waver',name='WaveGen', freq=f0 ,amp=1, pushed=True) 20 | 21 | 22 | machine.AddCircuit(type='opAdd', name='summer', in2=0) 23 | 24 | machine.Connect('WaveGen.cos','LockInAmp.signal') 25 | #machine.Connect('LockInAmp.RefWave','canti.exciter') 26 | #machine.Connect('canti.ztip','amp.signal') 27 | 28 | machine.Connect('summer.out','LockInAmp.CentFreq') 29 | 30 | 31 | 32 | out1 = machine.AddCircuit(type='output',name='output',file='LockInTest.dat', dump=0) 33 | #out1.Register('global.time','canti.ztip','LockInAmp.RefWave','LockInAmp.Amp','LockInAmp.Phase','amp.amp','summer.out') 34 | out1.Register('summer.out','LockInAmp.amp') 35 | 36 | 37 | freq =f0-1000 38 | 39 | while freq < (f0+1000): 40 | machine.SetInput(channel="summer.in1", value=freq) 41 | machine.Wait(0.1) 42 | out1.Dump() 43 | freq += 100 44 | -------------------------------------------------------------------------------- /examples/MgOFmAfm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | from customs import * 4 | 5 | 6 | def main(): 7 | 8 | machine = Machine(name='machine', dt=5e-8, pushed=True); 9 | f0 = 100000.0 10 | 11 | #Add Circuits 12 | canti = machine.AddCircuit(type='Cantilever',name='canti', startingz=0.5, 13 | Q=10000, k=167.0, f0=f0, pushed=True) 14 | 15 | machine.AddCircuit(type='delay', name='phi', DelayTime=0.5/f0, pushed=True) 16 | machine.AddCircuit(type='Machine', name='ampd', assembly=aAMPD, fcut=10000, pushed=True) 17 | machine.AddCircuit(type='PI', name='agc', Kp=1.1, Ki=800, set=1, pushed=True) 18 | 19 | machine.AddCircuit(type='Machine',name='pll',assembly=aPLL,filters=[10000,5000,2000], 20 | gain=500.0, f0=f0, Kp=0.5, Ki=800, pushed=True) 21 | machine.AddCircuit(type='opMul',name='exciter',pushed=True) 22 | 23 | #machine.AddCircuit(type='waver', name='wave', freq=100000.0, pushed=True) 24 | scanner = machine.AddCircuit(type='Scanner',name='scan', Process = machine, pushed=True) 25 | 26 | 27 | inter = machine.AddCircuit(type='i3Dlin',name='inter', components=1, pushed=True) 28 | inter.Configure(steps=[0.254375,0.254375,0.5], npoints=[32,32,8]) 29 | inter.Configure(pbc=[True,True,False]) 30 | inter.Configure(ForceMultiplier=1.60217646) 31 | inter.ReadData('forces_mg.in') 32 | 33 | 34 | 35 | #Imaging output 36 | imager = machine.AddCircuit(type='output',name='image',file='MgO.dat', dump=0) 37 | imager.Register("scan.x","scan.y","pll.df") 38 | 39 | 40 | #Debug output 41 | #out1 = machine.AddCircuit(type='output',name='output',file='Debug.dat', dump=1) 42 | #out1.Register('global.time', "scan.x", "scan.y", "scan.z", 'image.record',"canti.zabs") 43 | 44 | #feed x and y to interpolation 45 | machine.Connect("scan.x" , "inter.x") 46 | machine.Connect("scan.y" , "inter.y") 47 | 48 | #feed z to cantilever then the ztip of canti to interpolation 49 | machine.Connect("scan.z" , "canti.holderz") 50 | machine.Connect("canti.zabs" , "inter.z") 51 | 52 | #feed force to canti 53 | machine.Connect("inter.F1" , "canti.fz") 54 | 55 | 56 | 57 | machine.Connect('canti.ztip','ampd.signal') 58 | machine.Connect('ampd.amp','agc.signal') 59 | 60 | machine.Connect("ampd.norm","phi.signal") 61 | machine.Connect("phi.out","pll.signal1") 62 | machine.Connect("pll.cos","pll.signal2") 63 | 64 | machine.Connect('agc.out','exciter.in1') 65 | machine.Connect('pll.cos','exciter.in2') 66 | machine.Connect('exciter.out','canti.exciter') 67 | 68 | 69 | machine.Connect("scan.record","image.record") 70 | 71 | #machine.SetInput(channel="output.record", value=0) 72 | 73 | scanner.Place(x=0.254375,y=0.254375,z=3) 74 | 75 | scanner.Move(x=0,y=0,z=-0.5) 76 | machine.Wait(0.02) 77 | 78 | #machine.SetInput(channel="output.record", value=1) 79 | scanner.Recorder = imager 80 | scanner.BlankLines = True 81 | #resolution of the image [# points per line, # lines] 82 | scanner.Resolution = [64,64] 83 | scanner.ImageArea(16.28,16.28) 84 | #scan 85 | scanner.ScanArea() 86 | 87 | 88 | 89 | if __name__ == '__main__': 90 | main() 91 | 92 | -------------------------------------------------------------------------------- /examples/NaClFmAfm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | from customs import * 5 | 6 | 7 | def main(): 8 | 9 | 10 | machine = Machine(name='machine', dt=5e-8, pushed=True); 11 | f0 = 100000.0 12 | 13 | #Add Circuits 14 | canti = machine.AddCircuit(type='Cantilever',name='canti', startingz=0.5, 15 | Q=10000, k=167.0, f0=f0, pushed=True) 16 | 17 | machine.AddCircuit(type='delay', name='phi', DelayTime=0.5/f0, pushed=True) 18 | machine.AddCircuit(type='Machine', name='ampd', assembly=aAMPD, fcut=10000, pushed=True) 19 | machine.AddCircuit(type='PI', name='agc', Kp=1.1, Ki=800, set=1, pushed=True) 20 | 21 | machine.AddCircuit(type='Machine',name='pll',assembly=aPLL,filters=[10000,5000,2000], 22 | gain=500.0, f0=f0, Kp=0.5, Ki=800, pushed=True) 23 | machine.AddCircuit(type='opMul',name='exciter',pushed=True) 24 | 25 | #machine.AddCircuit(type='waver', name='wave', freq=100000.0, pushed=True) 26 | scanner = machine.AddCircuit(type='Scanner',name='scan', Process = machine, pushed=True) 27 | 28 | 29 | inter = machine.AddCircuit(type='i3Dlin',name='inter', components=3, pushed=True) 30 | inter.Configure(steps=[0.805714285714286,0.805714285714286,0.1], npoints=[8,8,171]) 31 | inter.Configure(pbc=[True,True,False]) 32 | inter.Configure(ForceMultiplier=1e10) 33 | inter.ReadData('NaClforces.dat') 34 | 35 | 36 | 37 | #Imaging output 38 | imager = machine.AddCircuit(type='output',name='image',file='NaCl.dat', dump=0) 39 | imager.Register("scan.x","scan.y","pll.df") 40 | 41 | 42 | #Debug output 43 | #out1 = machine.AddCircuit(type='output',name='output',file='Debug.dat', dump=1) 44 | #out1.Register('global.time', "scan.x", "scan.y", "scan.z", 'image.record',"canti.zabs") 45 | 46 | #feed x and y to interpolation 47 | machine.Connect("scan.x" , "inter.x") 48 | machine.Connect("scan.y" , "inter.y") 49 | 50 | #feed z to cantilever then the ztip of canti to interpolation 51 | machine.Connect("scan.z" , "canti.holderz") 52 | machine.Connect("canti.zabs" , "inter.z") 53 | 54 | #feed force to canti 55 | machine.Connect("inter.F3" , "canti.fz") 56 | 57 | 58 | 59 | machine.Connect('canti.ztip','ampd.signal') 60 | machine.Connect('ampd.amp','agc.signal') 61 | 62 | machine.Connect("ampd.norm","phi.signal") 63 | machine.Connect("phi.out","pll.signal1") 64 | machine.Connect("pll.cos","pll.signal2") 65 | 66 | machine.Connect('agc.out','exciter.in1') 67 | machine.Connect('pll.cos','exciter.in2') 68 | machine.Connect('exciter.out','canti.exciter') 69 | 70 | 71 | machine.Connect("scan.record","image.record") 72 | 73 | 74 | 75 | #machine.SetInput(channel="output.record", value=0) 76 | 77 | scanner.Place(x=0.805714285714286,y=0.805714285714286,z=4.5) 78 | 79 | scanner.Move(x=0,y=0,z=-0.5) 80 | machine.Wait(0.02) 81 | 82 | #machine.SetInput(channel="output.record", value=1) 83 | scanner.Recorder = imager 84 | scanner.BlankLines = True 85 | #resolution of the image [# points per line, # lines] 86 | scanner.Resolution = [64,1] 87 | scanner.ImageArea(11.68,11.68) 88 | #scan 89 | scanner.ScanArea() 90 | 91 | 92 | 93 | if __name__ == '__main__': 94 | main() 95 | 96 | -------------------------------------------------------------------------------- /examples/NaClTest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | from customs import * 4 | 5 | 6 | def main(): 7 | 8 | machine = Machine(machine=None, name='machine', dt=5.0e-8) 9 | # canti = machine.AddCircuit(type='Cantilever',name='canti', 10 | # Q=20000, k=26.4, f0=150000, startingz=1, pushed=True) 11 | 12 | 13 | canti = machine.AddCircuit(type='Cantilever',name='canti', startingz=1, 14 | Q=10000, k=167.0, f0=15000, pushed=True) 15 | 16 | machine.AddCircuit(type='waver',name='wave',freq=15000,amp=1) 17 | 18 | machine.AddCircuit(type="Machine",name='amp', fcut=10000, assembly=aAMPD, 19 | pushed=True) 20 | 21 | # machine.AddCircuit(type="PI",name='agc', Ki=2.1, Kp=0.1, set=0.1, pushed=True) 22 | machine.AddCircuit(type='PI', name='agc', Kp=1.1, Ki=800, set=1, pushed=True) 23 | machine.AddCircuit(type="limiter",name='agclim', min=0,max=10, pushed=True) 24 | 25 | machine.AddCircuit(type="Machine",name='pll', fcut=1000, assembly=aPLL, 26 | filters=[10000,5000,2000], gain=600.0, f0=15000, Kp=0.5, Ki=700, 27 | pushed=True) 28 | 29 | machine.AddCircuit(type='opMul',name='pllinv',in2=-1, pushed=True) 30 | machine.AddCircuit(type='opMul',name='exc', pushed=True) 31 | 32 | scanner = machine.AddCircuit(type='Scanner',name='scan', Process = machine, pushed=True) 33 | 34 | 35 | inter = machine.AddCircuit(type='i3Dlin',name='inter', components=3, pushed=True) 36 | inter.Configure(steps=[0.705,0.705,0.1], npoints=[8,8,201]) 37 | inter.Configure(pbc=[True,True,False]) 38 | inter.Configure(ForceMultiplier=1e10) 39 | inter.ReadData('NaClforces.dat') 40 | 41 | 42 | 43 | 44 | 45 | #Outputs 46 | out1 = machine.AddCircuit(type='output',name='output',file='testafm.out', dump=2) 47 | out1.Register('global.time', 'canti.zabs','amp.norm','pll.cos','pll.sin','exc.in2') 48 | #out1.Register('global.time', 'wave.cos','pll.cos','pll.sin','exc.in2') 49 | out1.Stop() 50 | 51 | out2 = machine.AddCircuit(type='output',name='output2',file='testafm2.out', dump=100) 52 | out2.Register('global.time', 'canti.ztip','agc.out','pll.df',"canti.fz") 53 | #out2.Stop() 54 | 55 | #Imaging output 56 | imager = machine.AddCircuit(type='output',name='image',file='NaCl.dat', dump=0) 57 | imager.Register("scan.x","scan.y","pll.df") 58 | 59 | 60 | #feed x and y to interpolation 61 | machine.Connect("scan.x" , "inter.x") 62 | machine.Connect("scan.y" , "inter.y") 63 | machine.Connect("scan.z" , "canti.holderz") 64 | machine.Connect("canti.zabs" , "inter.z") 65 | 66 | #Force 67 | machine.Connect("inter.F3" , "canti.fz") 68 | 69 | machine.Connect('canti.ztip','amp.signal') 70 | machine.Connect('amp.amp','agc.signal') 71 | machine.Connect('amp.norm','pll.signal1') 72 | #machine.Connect('wave.cos','pll.signal1') 73 | machine.Connect('pll.sin','pll.signal2') 74 | 75 | machine.Connect('agc.out','agclim.signal') 76 | machine.Connect('agclim.out','exc.in1') 77 | machine.Connect('pll.sin','pllinv.in1') 78 | machine.Connect('pllinv.out','exc.in2') 79 | 80 | machine.Connect('exc.out','canti.exciter') 81 | 82 | machine.Connect("scan.record","image.record") 83 | 84 | 85 | 86 | 87 | 88 | ''' 89 | machine.Wait(0.01) 90 | out1.Start() 91 | machine.Wait(0.001) 92 | out1.Stop() 93 | machine.Wait(0.05) 94 | out1.Start() 95 | machine.Wait(0.001) 96 | ''' 97 | #plot testafm.out 1:3 (canti) 1:4 (pll reference) 1:6 (the exciter) 98 | #u should see 3 distinct waves, canti peaks are in the middle between the other 2 99 | 100 | scanner.Place(x=0,y=0,z=15) 101 | machine.Wait(0.2) 102 | 103 | scanner.Move(x=0,y=0,z=-11) 104 | machine.Wait(1) 105 | 106 | 107 | 108 | 109 | #machine.SetInput(channel="output.record", value=1) 110 | scanner.Recorder = imager 111 | scanner.BlankLines = True 112 | #resolution of the image [# points per line, # lines] 113 | scanner.Resolution = [64,64] 114 | scanner.ImageArea(11.28,11.28) 115 | #scan 116 | scanner.ScanArea() 117 | 118 | 119 | if __name__ == '__main__': 120 | main() 121 | 122 | -------------------------------------------------------------------------------- /examples/NaClTestTwo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | from customs import * 4 | 5 | 6 | machine = Machine(machine=None, name='machine', dt=5.0e-8) 7 | 8 | 9 | canti = machine.AddCircuit(type='Cantilever',name='canti', startingz=1,Q=10000, k=167.0, f0=150000, pushed=True) 10 | 11 | 12 | machine.AddCircuit(type="Machine",name='amp', fcut=10000, assembly=aAMPD, pushed=True) 13 | 14 | machine.AddCircuit(type='PI', name='agc', Kp=1.1, Ki=800, set=1, pushed=True) 15 | machine.AddCircuit(type="limiter",name='agclim', min=-100000,max=1000000, pushed=True) 16 | 17 | machine.AddCircuit(type="Machine",name='pll', fcut=1000, assembly=aPLL, filters=[10000,5000,2000], gain=600.0, f0=150000, Kp=0.5, Ki=700, pushed=True) 18 | 19 | machine.AddCircuit(type='opMul',name='pllinv',in2=-1, pushed=True) 20 | machine.AddCircuit(type='opMul',name='exc', pushed=True) 21 | 22 | scanner = machine.AddCircuit(type='Scanner',name='scan', Process = machine, pushed=True) 23 | 24 | 25 | inter = machine.AddCircuit(type='i3Dlin',name='inter', components=3, pushed=True) 26 | inter.Configure(steps=[0.705,0.705,0.1], npoints=[8,8,201]) 27 | inter.Configure(pbc=[True,True,False]) 28 | inter.Configure(ForceMultiplier=1e10) 29 | inter.ReadData('NaClforces.dat') 30 | 31 | 32 | 33 | 34 | 35 | #Outputs 36 | out1 = machine.AddCircuit(type='output',name='output',file='testafm.out', dump=2) 37 | out1.Register('global.time', 'canti.zabs','amp.norm','pll.cos','pll.sin','exc.in2') 38 | out1.Stop() 39 | 40 | out2 = machine.AddCircuit(type='output',name='output2',file='testafm2.out', dump=10000) 41 | out2.Register('global.time', 'canti.ztip','agc.out','pll.df',"canti.fz","scan.z","inter.F3") 42 | out2.Stop() 43 | 44 | #Imaging output 45 | imager = machine.AddCircuit(type='output',name='image',file='NaCl.dat', dump=0) 46 | imager.Register("scan.x","scan.y","pll.df") 47 | 48 | 49 | #feed x and y to interpolation 50 | machine.Connect("scan.x" , "inter.x") 51 | machine.Connect("scan.y" , "inter.y") 52 | machine.Connect("scan.z" , "canti.holderz") 53 | machine.Connect("canti.zabs" , "inter.z") 54 | 55 | #Force 56 | machine.Connect("inter.F3" , "canti.fz") 57 | 58 | machine.Connect('canti.ztip','amp.signal') 59 | machine.Connect('amp.amp','agc.signal') 60 | machine.Connect('amp.norm','pll.signal1') 61 | machine.Connect('pll.cos','pll.signal2') 62 | 63 | machine.Connect('agc.out','agclim.signal') 64 | machine.Connect('agclim.out','exc.in1') 65 | machine.Connect('pll.cos','pllinv.in1') 66 | machine.Connect('pllinv.out','exc.in2') 67 | 68 | machine.Connect('exc.out','canti.exciter') 69 | 70 | machine.Connect("scan.record","image.record") 71 | 72 | 73 | 74 | 75 | scanner.Place(x=0.705,y=0.705,z=15) 76 | machine.Wait(0.1) 77 | out2.Start() 78 | #scanner.Move(x=0,y=0,z=-11) 79 | #machine.Wait(0.1) 80 | 81 | #scanner.Move(x=0,y=0,z=10) 82 | 83 | 84 | scanner.Recorder = imager 85 | scanner.BlankLines = True 86 | #resolution of the image [# points per line, # lines] 87 | scanner.Resolution = [20,20] 88 | scanner.ImageArea(11.28,11.28) 89 | #scan 90 | scanner.ScanArea() -------------------------------------------------------------------------------- /examples/PyVAFM cirucit tut.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SINGROUP/PyVAFM/ac77316fe07818261e3d5c9405d8ccf9ef7508ff/examples/PyVAFM cirucit tut.pdf -------------------------------------------------------------------------------- /examples/VDWtest.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | TipAngle=0.28658 4 | TipHamak=39.6e-20 5 | TipRadius=3.9487 6 | TipOffset=0 7 | 8 | g2r = math.pi/180 9 | sing = math.sin(TipAngle*g2r); 10 | tang = math.tan(TipAngle*g2r); 11 | cosg = math.cos(TipAngle*g2r); 12 | cos2g= math.cos(TipAngle*g2r*2.0); 13 | 14 | 15 | TR2 = TipRadius*TipRadius; 16 | TRC = TipRadius*cos2g; 17 | TRS = TipRadius*sing; 18 | TipHamak = TipHamak* 1.0e18; 19 | 20 | for ztip in range(100, 1000): 21 | ztip = ztip*0.01 22 | vdw = (TipHamak*TR2)*(1.0-sing)*(TRS-ztip*sing-TipRadius-ztip); 23 | vdw/= (6.0*(ztip*ztip)*(TipRadius+ztip-TRS)*(TipRadius+ztip-TRS)); 24 | vdw-= (TipHamak*tang*(ztip*sing+TRS+TRC))/(6.0*cosg*(TipRadius+ztip-TRS)*(TipRadius+ztip-TRS)); 25 | print ztip, vdw -------------------------------------------------------------------------------- /examples/benchmark_cCore.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmbase import ChannelType 4 | from vafmcircuits import Machine 5 | 6 | import vafmcircuits 7 | import vafmcircuits_pycirc 8 | 9 | from datetime import datetime 10 | 11 | 12 | 13 | def main(): 14 | startTime = datetime.now() 15 | 16 | machine = Machine(name='machine', dt=0.01, pushed=True); 17 | 18 | wave = machine.AddCircuit(type='waver',name='wave', amp=1, freq=1, pushed=True ) 19 | #adder= machine.AddCircuit(type='myCirc',name='add_0', pushed=True) 20 | adder= machine.AddCircuit(type='myCirc',name='add_0', pushed=True) 21 | # adder= machine.AddCircuit(type='myCirc',name='add_1', pushed=True) 22 | # adder= machine.AddCircuit(type='myCirc',name='add_2', pushed=True) 23 | # adder= machine.AddCircuit(type='myCirc',name='add_3', pushed=True) 24 | # adder= machine.AddCircuit(type='myCirc',name='add_4', pushed=True) 25 | # adder= machine.AddCircuit(type='myCirc',name='add_5', pushed=True) 26 | # adder= machine.AddCircuit(type='myCirc',name='add_6', pushed=True) 27 | # adder= machine.AddCircuit(type='myCirc',name='add_7', pushed=True) 28 | # adder= machine.AddCircuit(type='myCirc',name='add_8', pushed=True) 29 | # adder= machine.AddCircuit(type='myCirc',name='add_9', pushed=True) 30 | 31 | machine.Connect('wave.cos','add_0.in1') 32 | machine.Connect('wave.sin','add_0.in2') 33 | for i in xrange(1,10): 34 | addname = "add_"+str(i) 35 | prvname = "add_"+str(i-1) 36 | adder= machine.AddCircuit(type='opMul',name=addname, pushed=True) 37 | machine.Connect(prvname+".out",addname+'.in1') 38 | machine.Connect('wave.sin',addname+'.in2') 39 | 40 | 41 | #machine.Wait(100000.0) #10^7 steps - 1.414s - TPS = 7072135.785 - PURE cCORE 42 | #machine.Wait(10000.0) #10^6 steps - 3.222s - TPS = 310366.232 - cCORE + 1 PYCircuit 43 | #machine.WaitPY(1000.0) #10^5 steps - 8.265s - TPS = 12099.2130 - PURE PY 44 | 45 | print(datetime.now()-startTime) 46 | if __name__ == '__main__': 47 | main() 48 | -------------------------------------------------------------------------------- /examples/example_composite.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmbase import ChannelType 4 | from vafmcircuits import Machine 5 | 6 | import vafmcircuits 7 | import vafmcircuits_math 8 | 9 | 10 | def ADC(compo,**keys): 11 | 12 | compo.AddInput("signal1") 13 | compo.AddInput("signal2") 14 | compo.AddOutput("out") 15 | compo.AddCircuit(type='opAdd',name='adder',factors=2, pushed=True) 16 | compo.Connect("global.signal1","adder.in1") 17 | compo.Connect("global.signal2","adder.in2") 18 | compo.Connect("adder.out","global.out") 19 | 20 | print "ADC assemb led!" 21 | 22 | def main(): 23 | 24 | 25 | machine = Machine(name='machine', dt=0.01, pushed=True); 26 | 27 | 28 | #Add Circuits 29 | 30 | 31 | osc = machine.AddCircuit(type='waver',name='osc', amp=1, freq=1, pushed=True ) 32 | 33 | compo1 = machine.AddCircuit(type='Machine', name='compo1', assembly=ADC, pushed=True) 34 | 35 | out1 = machine.AddCircuit(type='output',name='output',file='example_composite.log', dump=1) 36 | out1.Register('global.time', 'osc.sin', 'osc.cos', 'compo1.out') 37 | 38 | machine.Connect("osc.sin","compo1.signal1") 39 | machine.Connect("osc.cos","compo1.signal2") 40 | 41 | machine.Wait(10) 42 | 43 | 44 | if __name__ == '__main__': 45 | main() 46 | -------------------------------------------------------------------------------- /examples/example_filter.dox: -------------------------------------------------------------------------------- 1 | /*! \page page_ex_filter Filter 2 | 3 | asd 4 | 5 | 6 | */ 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/johntest/NaClTest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | from customs_pll import * 4 | 5 | 6 | ''' 7 | UNITS: 8 | distance = nm 9 | force = nN 10 | time = s 11 | ''' 12 | 13 | def main(): 14 | 15 | machine = Machine(machine=None, name='machine', dt=5.0e-8) 16 | # canti = machine.AddCircuit(type='Cantilever',name='canti', 17 | # Q=20000, k=26.4, f0=150000, startingz=1, pushed=True) 18 | 19 | A0 = 0.2 20 | 21 | canti = machine.AddCircuit(type='Cantilever',name='canti', startingz=0.5*A0, 22 | Q=10000, k=167.0, f0=150000, pushed=True) 23 | 24 | #machine.AddCircuit(type='waver',name='wave',freq=150000,amp=1) 25 | 26 | #Amplitude stuff: I changed the settings a bit so the noise is less than 1 pm 27 | machine.AddCircuit(type="Machine",name='amp', fcut=5000, assembly=aAMPD, 28 | pushed=True) 29 | machine.AddCircuit(type='PI', name='agc', Kp=1.0, Ki=100, set=A0, pushed=True) 30 | machine.AddCircuit(type="limiter",name='agclim', min=0,max=10, pushed=True) 31 | 32 | machine.AddCircuit(type="Machine",name='pll', fcut=1000, assembly=aPLL, 33 | filters=[10000,5000,2000], gain=600.0, f0=150000, Kp=0.5, Ki=700, 34 | pushed=True) 35 | 36 | machine.AddCircuit(type='opMul',name='pllinv',in2=-1, pushed=True) 37 | machine.AddCircuit(type='opMul',name='exc', pushed=True) 38 | 39 | scanner = machine.AddCircuit(type='Scanner',name='scan', Process = machine, pushed=True) 40 | 41 | 42 | inter = machine.AddCircuit(type='i3Dlin',name='inter', components=3, pushed=True) 43 | inter.Configure(steps=[0.0705,0.0705,0.01], npoints=[8,8,201]) # I converted it back to nN 44 | inter.Configure(pbc=[True,True,False]) 45 | inter.Configure(ForceMultiplier=1e9) # I converted it back to nN 46 | inter.ReadData('NaClforces.dat') 47 | 48 | 49 | #Outputs 50 | out1 = machine.AddCircuit(type='output',name='output',file='testafm.out', dump=2) 51 | out1.Register('global.time', 'canti.zabs','amp.norm','pll.cos','pll.sin','exc.in2') 52 | #out1.Register('global.time', 'wave.cos','pll.cos','pll.sin','exc.in2') 53 | out1.Stop() 54 | 55 | out2 = machine.AddCircuit(type='output',name='output2',file='testafm2.out', dump=100000) 56 | out2.Register('global.time', 'amp.amp','agc.out','pll.df',"canti.fz",'scan.z')#always monitor the amplitude 57 | 58 | 59 | #Imaging output 60 | imager = machine.AddCircuit(type='output',name='image',file='NaCl.dat', dump=0) 61 | imager.Register("scan.x","scan.y","pll.df","amp.amp") 62 | 63 | 64 | #feed x and y to interpolation 65 | machine.Connect("scan.x" , "inter.x") 66 | machine.Connect("scan.y" , "inter.y") 67 | machine.Connect("scan.z" , "canti.holderz") 68 | machine.Connect("canti.zabs" , "inter.z") 69 | 70 | #Force 71 | machine.Connect("inter.F3" , "canti.fz") 72 | 73 | machine.Connect('canti.ztip','amp.signal') 74 | machine.Connect('amp.amp','agc.signal') 75 | machine.Connect('amp.norm','pll.signal1') 76 | #machine.Connect('wave.cos','pll.signal1') 77 | machine.Connect('pll.cos','pll.signal2') 78 | 79 | machine.Connect('agc.out','agclim.signal') 80 | machine.Connect('agclim.out','exc.in1') 81 | machine.Connect('pll.cos','pllinv.in1') 82 | machine.Connect('pllinv.out','exc.in2') 83 | 84 | machine.Connect('exc.out','canti.exciter') 85 | 86 | machine.Connect("scan.record","image.record") 87 | 88 | 89 | ''' 90 | machine.Wait(0.01) 91 | out1.Start() 92 | machine.Wait(0.001) 93 | out1.Stop() 94 | machine.Wait(0.05) 95 | out1.Start() 96 | machine.Wait(0.001) 97 | ''' 98 | #plot testafm.out 1:3 (canti) 1:4 (pll reference) 1:6 (the exciter) 99 | #u should see 3 distinct waves, canti peaks are in the middle between the other 2 100 | 101 | holderstartz = 3 #start at 3nm high 102 | 103 | out2.Stop() 104 | scanner.Place(x=0,y=0,z=holderstartz) 105 | machine.Wait(0.1) # prerelaxation we do not want to see in out2 106 | out2.Start() 107 | machine.Wait(0.5) #these does not give any visual feedback.... we dont know if the program crashed! 108 | 109 | scanner.FastSpeed = 10 # approach faster 110 | 111 | #amp is 1nm, to image at a min approach distance of 5 angs, 112 | #we need to approach by 15nm-amp-0.5nm 113 | scanner.Move(x=0,y=0,z=-(holderstartz-A0-0.5)) 114 | machine.Wait(1) 115 | 116 | 117 | machine.SetInput(channel="output.record", value=1) 118 | scanner.Recorder = imager 119 | scanner.BlankLines = True 120 | #resolution of the image [# points per line, # lines] 121 | scanner.Resolution = [512,512] 122 | scanner.ImageArea(1.128,1.128) 123 | scanner.FastSpeed = 10 124 | scanner.SlowSpeed = 10 125 | #scan 126 | scanner.ScanArea() 127 | 128 | 129 | if __name__ == '__main__': 130 | main() 131 | 132 | -------------------------------------------------------------------------------- /examples/johntest/test_STM.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | 4 | def main(): 5 | 6 | machine = Machine(machine=None, name='machine', dt=0.01) 7 | 8 | scanner = machine.AddCircuit(type='Scanner',name='scan', pushed=True ) 9 | 10 | inter = machine.AddCircuit(type='i4Dlin',name='inter', components=1, pushed=True) 11 | inter.BiasStep=0.5 12 | inter.StartingV=2 13 | inter.ConfigureVASP(pbc=[True,True,False,False]) 14 | inter.ReadVASPData("parchg.2.0") 15 | 16 | 17 | machine.AddCircuit(type='STM',name='STM', pushed=True) 18 | 19 | out1 = machine.AddCircuit(type='output',name='output',file='testSTM.dat', dump=1) 20 | out1.Register('scan.x', 'scan.y','scan.z','STM.Current','inter.F1') 21 | 22 | 23 | imager = machine.AddCircuit(type='output',name='image',file='STM.dat', dump=0) 24 | imager.Register("scan.x","scan.y",'STM.Current','inter.F1') 25 | 26 | machine.Connect("scan.x","inter.x") 27 | machine.Connect("scan.y","inter.y") 28 | machine.Connect("scan.z","inter.z") 29 | machine.Connect("inter.F1","STM.Density") 30 | machine.Connect("scan.record","image.record") 31 | 32 | 33 | machine.circuits['inter'].I['V'].Set(2) 34 | scanner.Place(x=0,y=0,z=13) 35 | 36 | 37 | scanner.Recorder = imager 38 | scanner.BlankLines = True 39 | #resolution of the image [# points per line, # lines] 40 | scanner.Resolution = [50,50] 41 | scanner.ImageArea(18,16) 42 | #scan 43 | scanner.ScanArea() 44 | 45 | if __name__ == '__main__': 46 | main() 47 | -------------------------------------------------------------------------------- /examples/johntest/test_STM_ConstantCurrent.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | 4 | def main(): 5 | 6 | 7 | 8 | machine = Machine(machine=None, name='machine', dt=0.01) 9 | 10 | scanner = machine.AddCircuit(type='Scanner',name='scan', pushed=True ) 11 | 12 | inter = machine.AddCircuit(type='i4Dlin',name='inter', components=1, pushed=True) 13 | inter.BiasStep=0.5 14 | inter.StartingV=2 15 | inter.ConfigureVASP(pbc=[True,True,False,False]) 16 | inter.ReadVASPData("parchg.2.0") 17 | 18 | 19 | machine.AddCircuit(type='STM',name='STM', pushed=True) 20 | 21 | out1 = machine.AddCircuit(type='output',name='output',file='testSTM.dat', dump=1) 22 | out1.Register('scan.x', 'scan.y','scan.z','STM.Current','inter.F1') 23 | 24 | 25 | imager = machine.AddCircuit(type='output',name='image',file='STM.dat', dump=0) 26 | imager.Register("scan.x","scan.y",'STM.Current','inter.F1') 27 | 28 | machine.Connect("scan.x","inter.x") 29 | machine.Connect("scan.y","inter.y") 30 | machine.Connect("scan.z","inter.z") 31 | machine.Connect("inter.F1","STM.Density") 32 | machine.Connect("scan.record","image.record") 33 | 34 | 35 | machine.circuits['inter'].I['V'].Set(2) 36 | scanner.Place(x=0,y=0,z=5) 37 | 38 | 39 | scanner.Recorder = imager 40 | scanner.BlankLines = True 41 | #resolution of the image [# points per line, # lines] 42 | scanner.Resolution = [50,50] 43 | scanner.ImageArea(18,16) 44 | #scan 45 | scanner.ScanArea() 46 | 47 | if __name__ == '__main__': 48 | main() 49 | -------------------------------------------------------------------------------- /examples/johntest/vafmcore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SINGROUP/PyVAFM/ac77316fe07818261e3d5c9405d8ccf9ef7508ff/examples/johntest/vafmcore.so -------------------------------------------------------------------------------- /examples/makeFF.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | 4 | def main(): 5 | 6 | machine = Machine(machine=None, name='machine', dt=0.01) 7 | 8 | machine.AddCircuit(type='Dipole',name='Dipole', OutputFilename="Cerium.dat",PotentialFilename ="host.LOCPOT" ,pushed=True) 9 | 10 | # machine.AddCircuit(type='PlotAtoms',name='PlotAtoms', Filename ="ceo2_111_host_ortho.LOCPOT" ,pushed=True) 11 | 12 | 13 | if __name__ == '__main__': 14 | main() 15 | -------------------------------------------------------------------------------- /examples/quickstart.py: -------------------------------------------------------------------------------- 1 | from vafmcircuits import Machine 2 | 3 | machine = Machine(name='machine', dt=0.01) 4 | 5 | machine.AddCircuit(type='waver', name='osc', freq=1.2, amp=1) 6 | 7 | machine.AddCircuit(type='opAdd', name='adder', factors=2) 8 | 9 | machine.Connect('osc.sin','adder.in1') 10 | machine.Connect('osc.cos','adder.in2') 11 | 12 | logger = machine.AddCircuit(type='output', name='logger', file='tutorial_basic.out', dump=1) 13 | logger.Register('global.time','osc.sin','osc.cos','adder.out') 14 | 15 | machine.Wait(3) -------------------------------------------------------------------------------- /examples/realtimer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | def main(): 7 | 8 | 9 | machine = Machine(machine=None, name='machine', dt=0.01, pushed=False); 10 | 11 | 12 | #Add Circuits 13 | machine.AddCircuit(type='waver',name='wave', amp=0.5, freq=10, pushed = False) 14 | machine.AddCircuit(type='opAdd', name='add', pushed = False) 15 | 16 | 17 | #Connections 18 | machine.Connect("wave.sin","add.in1") 19 | machine.Connect("wave.cos","add.in2") 20 | 21 | #Outputs 22 | out1 = machine.AddCircuit(type='output',name='output',file='log.dat', dump=1) 23 | out1.Register('global.time', 'wave.sin', 'wave.sin', 'add.out') 24 | out1.Plot(sizex=5, sizey = 3, RealTime = True) 25 | 26 | 27 | machine.Wait(2) 28 | 29 | if __name__ == '__main__': 30 | main() 31 | -------------------------------------------------------------------------------- /examples/test.py: -------------------------------------------------------------------------------- 1 | ##!/usr/bin/env python 2 | import subprocess 3 | import sys 4 | sys.path.append('/Users/johntracey/Desktop/pyvafm-master/src') 5 | 6 | from vafmbase import ChannelType 7 | from vafmcircuits import Machine 8 | 9 | import vafmcircuits 10 | 11 | 12 | 13 | 14 | #main machine 15 | machine = Machine(name='machine', dt=0.0001, pushed=True) 16 | 17 | # wave generator 18 | machine.AddCircuit(type='waver',name='wave', amp=1, freq=2, phi=1, offset=2.0, pushed=True) 19 | machine.AddCircuit(type='square',name='sqw', amp=1.5, freq=2, offset=0.0, duty=0.2, pushed=True ) 20 | machine.AddCircuit(type='opAdd',name='Add', pushed=True ) 21 | 22 | machine.Connect("wave.sin","Add.in1") 23 | machine.Connect("wave.sin","Add.in2") 24 | 25 | #output to file - dump=0 means only manual dump 26 | out1 = machine.AddCircuit(type='output',name='output',file='wavers.log', dump=1) 27 | out1.Register('global.time', 'wave.sin', 'wave.cos', 'wave.saw', 'sqw.out',"Add.out") 28 | 29 | 30 | machine.Wait(1) 31 | 32 | 33 | -------------------------------------------------------------------------------- /examples/test.py.org: -------------------------------------------------------------------------------- 1 | ##!/usr/bin/env python 2 | import subprocess 3 | import sys 4 | sys.path.append('/Users/johntracey/Desktop/pyvafm-master/src') 5 | 6 | from vafmbase import ChannelType 7 | from vafmcircuits import Machine 8 | 9 | import vafmcircuits 10 | 11 | 12 | 13 | 14 | #main machine 15 | machine = Machine(name='machine', dt=0.0001, pushed=True) 16 | 17 | # wave generator 18 | machine.AddCircuit(type='waver',name='wave', amp=1, freq=2, phi=1, offset=2.0, pushed=True) 19 | machine.AddCircuit(type='square',name='sqw', amp=1.5, freq=2, offset=0.0, duty=0.2, pushed=True ) 20 | machine.AddCircuit(type='opAdd',name='Add', pushed=True ) 21 | 22 | machine.Connect("wave.sin","Add.in1") 23 | machine.Connect("wave.sin","Add.in2") 24 | 25 | #output to file - dump=0 means only manual dump 26 | out1 = machine.AddCircuit(type='output',name='output',file='wavers.log', dump=1) 27 | out1.Register('global.time', 'wave.sin', 'wave.cos', 'wave.saw', 'sqw.out',"Add.out") 28 | 29 | 30 | machine.Wait(1) 31 | 32 | 33 | -------------------------------------------------------------------------------- /examples/test_AdvancedCantilever.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | from customs_pll import * 4 | 5 | def main(): 6 | 7 | 8 | machine = Machine(name='machine', dt=0.02, pushed=True); 9 | f0 = 100.0 10 | 11 | #Add Circuits 12 | canti = machine.AddCircuit(type='AdvancedCantilever',name='canti', NumberOfModesV=2, NumberOfModesL=1 ,pushed=True) 13 | scanner = machine.AddCircuit(type='Scanner',name='scan', pushed=True ) 14 | 15 | machine.AddCircuit(type='waver',name='wave', amp=10, freq=1, phi=1, offset=0, pushed=True) 16 | 17 | canti.AddMode(Vertical=True, k = 1, Q=100, M=1, f0 =1) 18 | canti.AddMode(Vertical=True, k = 1, Q=100, M=1, f0 =1) 19 | canti.AddMode(Vertical=False, k = 1, Q=100, M=1, f0 =1) 20 | canti.StartingPos(0,3,5) 21 | canti.CantileverReady() 22 | 23 | machine.Connect("scan.x","canti.Holderx") 24 | machine.Connect("scan.y","canti.Holdery") 25 | machine.Connect("scan.z","canti.Holderz") 26 | # machine.Connect("wave.cos","canti.ForceV") 27 | # machine.Connect("wave.cos","canti.ForceL") 28 | 29 | #debug output 30 | out1 = machine.AddCircuit(type='output',name='output',file='AdvCantilever.dat', dump=1) 31 | out1.Register("global.time","canti.zPos","canti.yPos","canti.xABS","canti.yABS","canti.zABS","canti.zV1","canti.zV2") 32 | 33 | 34 | scanner.Place(x=1,y=1,z=1) 35 | machine.Wait(15) 36 | 37 | if __name__ == '__main__': 38 | main() 39 | 40 | 41 | -------------------------------------------------------------------------------- /examples/test_CubeInterpolation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | 4 | def main(): 5 | 6 | machine = Machine(machine=None, name='machine', dt=0.01) 7 | 8 | inter = machine.AddCircuit(type='CubeFileInter',name='inter', components=1, pushed=True) 9 | #inter.Configure(pbc=[True,True,False]) 10 | #inter.ReadData("cosalen.cube") 11 | 12 | 13 | 14 | ''' 15 | 16 | scanner = machine.AddCircuit(type='Scanner',name='scan', pushed=True ) 17 | 18 | out1 = machine.AddCircuit(type='output',name='output',file='test4d.dat', dump=1) 19 | out1.Register('scan.x', 'scan.y','scan.z','inter.F1') 20 | 21 | #Imaging output 22 | imager = machine.AddCircuit(type='output',name='image',file='4d.dat', dump=0) 23 | imager.Register("scan.x","scan.y",'inter.F1') 24 | 25 | machine.Connect("scan.x","inter.x") 26 | machine.Connect("scan.y","inter.y") 27 | machine.Connect("scan.z","inter.z") 28 | machine.Connect("scan.record","image.record") 29 | 30 | 31 | machine.circuits['inter'].I['V'].Set(1.0) 32 | scanner.Place(x=0,y=0,z=15) 33 | #scanner.Move(x=16, v=1) 34 | 35 | scanner.Recorder = imager 36 | scanner.BlankLines = True 37 | #resolution of the image [# points per line, # lines] 38 | scanner.Resolution = [50,50] 39 | scanner.ImageArea(18,16) 40 | #scan 41 | scanner.ScanArea() 42 | ''' 43 | if __name__ == '__main__': 44 | main() 45 | -------------------------------------------------------------------------------- /examples/test_DFTVDW.py: -------------------------------------------------------------------------------- 1 | from vafmcircuits import Machine 2 | 3 | machine = Machine(name='machine', dt=0.0001, pushed=True); 4 | machine.AddCircuit(type='DFTD3',name='DFTD3',pushed=True,) -------------------------------------------------------------------------------- /examples/test_Dipole.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | 4 | def main(): 5 | 6 | machine = Machine(machine=None, name='machine', dt=0.01) 7 | 8 | machine.AddCircuit(type='CoordTransform',name='CT', LatticeVectorX=[15.562592,0.0,0.0], LatticeVectorY=[-7.781296,13.4776,0.0], LatticeVectorZ=[15.562592,-8.985067,25.413607] ,pushed=True) 9 | 10 | 11 | scan = machine.AddCircuit(type='Scanner',name='scann') 12 | inter = machine.AddCircuit(type='i3Dlin',name='inter', components=1) 13 | 14 | inter.Configure(steps=[0.072049037037, 0.0748755555556, 0.075635735119], npoints=[216,180,332]) 15 | inter.Configure(pbc=[True,True,False]) 16 | inter.ReadData('TestCeo2.dat') 17 | 18 | machine.Connect("scann.x" , "inter.x") 19 | machine.Connect("scann.y" , "inter.y") 20 | machine.Connect("scann.z" , "inter.z") 21 | 22 | #machine.Connect("CT.xprime","inter.x") 23 | #machine.Connect("CT.yprime","inter.y") 24 | #machine.Connect("CT.zprime","inter.z") 25 | 26 | 27 | #image output 28 | imager = machine.AddCircuit(type='output',name='image',file='CeriumFF.dat', dump=0) 29 | imager.Register("scann.x", "scann.y", 'inter.F1',) 30 | 31 | machine.Connect("scann.record", "image.record") 32 | 33 | scan.Place(x=0, y=0, z=13) 34 | #machine.Wait(0.01) 35 | 36 | #this will print an empty line after each scanline 37 | scan.Recorder = imager 38 | scan.BlankLines = True 39 | #not necessary, but it makes it easier for gnuplot 40 | 41 | #resolution of the image [# points per line, # lines] 42 | scan.Resolution = [256,256] 43 | scan.ImageArea(16,16) 44 | 45 | #scan 46 | scan.ScanArea() 47 | 48 | 49 | if __name__ == '__main__': 50 | main() 51 | -------------------------------------------------------------------------------- /examples/test_DipoleCircuit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | import math 4 | import numpy as np 5 | #################################### 6 | 7 | 8 | machine = Machine(machine=None, name='machine', dt=0.01) 9 | 10 | #machine.AddCircuit(type='LOCPOTShaping',name='LOCPOTShaping', OutputFilename="Ceria.dat",PotentialFilename="host.LOCPOT",ForcefieldSize=[15.562592,13.4776,25.413607] 11 | # ,ForcefieldStepSize=[0.072049037037,0.0748755555556,0.075635735119] 12 | # , LatticeVectora=[15.562592,0.0,0.0], LatticeVectorb=[-7.781296,13.4776,0.0], LatticeVectorc=[15.562592,-8.985067,25.413607] ,pushed=True) 13 | 14 | machine.AddCircuit(type='Dipole',name='Dipole',InputFile="Ceria.dat", OutputFile="FF.dat", stepsize= [0.072049037037,0.0748755555556,0.075635735119]) -------------------------------------------------------------------------------- /examples/test_FlipFlop.py: -------------------------------------------------------------------------------- 1 | ##!/usr/bin/env python 2 | import subprocess 3 | import sys 4 | sys.path.append('/Users/johntracey/Desktop/pyvafm-master/src') 5 | 6 | from vafmbase import ChannelType 7 | from vafmcircuits import Machine 8 | 9 | import vafmcircuits 10 | 11 | 12 | def main(): 13 | 14 | #main machine 15 | machine = Machine(name='machine', dt=0.01, pushed=True); 16 | 17 | # wave generator 18 | machine.AddCircuit(type='waver',name='wave', amp=1, freq=2, phi=0, offset=0, pushed=True) 19 | machine.AddCircuit(type='square',name='sqw', amp=0.7, freq=10, offset=0.0, duty=0.5, pushed=True ) 20 | 21 | machine.AddCircuit(type='SRFlipFlop', name='SR', pushed=True) 22 | machine.AddCircuit(type='JKFlipFlop', name='JK', pushed=True) 23 | machine.AddCircuit(type='DFlipFlop', name='D', pushed=True) 24 | machine.AddCircuit(type='DRFlipFlop', name='DR', pushed=True) 25 | 26 | 27 | 28 | #output to file - dump=0 means only manual dump 29 | out1 = machine.AddCircuit(type='output',name='output',file='flipflops.dat', dump=1) 30 | out1.Register('global.time', 'wave.sin', 'wave.cos', 'sqw.out', 'D.Q') 31 | 32 | 33 | 34 | machine.Connect('wave.sin','D.D') 35 | machine.Connect('wave.cos','JK.K') 36 | machine.Connect('sqw.out','D.clock') 37 | 38 | machine.Wait(1) 39 | 40 | 41 | 42 | if __name__ == '__main__': 43 | main() 44 | 45 | -------------------------------------------------------------------------------- /examples/test_GausSmear.py: -------------------------------------------------------------------------------- 1 | from vafmcircuits import Machine 2 | 3 | machine = Machine(name='machine', dt=0.0001, pushed=True); 4 | machine.AddCircuit(type='GausSmear',name='GS',pushed=True,Filename='host.LOCPOT',Sigma=0.1,OutputFilename='test.dat') -------------------------------------------------------------------------------- /examples/test_LOCPOT.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | 4 | def main(): 5 | 6 | machine = Machine(machine=None, name='machine', dt=0.01) 7 | 8 | inter = machine.AddCircuit(type='LOCPOTInter',name='inter', components=1, pushed=True) 9 | inter.ConfigureLOCPOT(pbc=[True,True,False]) 10 | inter.ReadLOCPOTData("parchg.1.0") 11 | 12 | 13 | scanner = machine.AddCircuit(type='Scanner',name='scan', pushed=True ) 14 | 15 | out1 = machine.AddCircuit(type='output',name='output',file='testLOCPOT.dat', dump=1) 16 | out1.Register('scan.x', 'scan.y','scan.z','inter.U') 17 | 18 | #Imaging output 19 | imager = machine.AddCircuit(type='output',name='image',file='LOCPOT.dat', dump=0) 20 | imager.Register("scan.x","scan.y",'inter.U') 21 | 22 | machine.Connect("scan.x","inter.x") 23 | machine.Connect("scan.y","inter.y") 24 | machine.Connect("scan.z","inter.z") 25 | machine.Connect("scan.record","image.record") 26 | 27 | #machine.circuits['inter'].I['V'].Set(1.0) 28 | scanner.Place(x=0,y=0,z=15) 29 | #scanner.Move(x=16, v=1) 30 | 31 | scanner.Recorder = imager 32 | scanner.BlankLines = True 33 | #resolution of the image [# points per line, # lines] 34 | scanner.Resolution = [50,50] 35 | scanner.ImageArea(18,16) 36 | #scan 37 | scanner.ScanArea() 38 | 39 | if __name__ == '__main__': 40 | main() 41 | -------------------------------------------------------------------------------- /examples/test_MechAFM.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | machine = Machine(name='machine', dt=0.0001, pushed=True); 6 | 7 | machine.AddCircuit(type="MechAFM",name="mechAFM",xyzfile="graphene.xyz",paramfile="parameters.dat", 8 | TipAtom="O", DummyAtom="X",PlaneAtom="C", MinTerm="f",etol=0.1,ftol=0.1, cfac=0.001, 9 | MaxSteps=50000, coulomb="on",zhigh=10.0,zlow=6.0,dx=0.5,dy=0.5,dz=0.1,bufsize=1000,InputFileName="test.in",MPICommand="/path/to/mpirun -np 1") 10 | -------------------------------------------------------------------------------- /examples/test_STM.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | 4 | def main(): 5 | 6 | machine = Machine(machine=None, name='machine', dt=0.01) 7 | 8 | 9 | scanner = machine.AddCircuit(type='Scanner',name='scan', pushed=True ) 10 | 11 | inter = machine.AddCircuit(type='i4DlinVasp',name='inter', components=1, pushed=True) 12 | inter.BiasStep=0.5 13 | inter.StartingV=2 14 | inter.ConfigureVASP(pbc=[True,True,False,False]) 15 | inter.ReadVASPData("parchg.2.0") 16 | 17 | machine.AddCircuit(type='STM',name='STM', pushed=True) 18 | 19 | 20 | 21 | out1 = machine.AddCircuit(type='output',name='output',file='testSTM2.dat', dump=1) 22 | out1.Register('scan.x', 'scan.y','scan.z','STM.Current','inter.F') 23 | 24 | 25 | imager = machine.AddCircuit(type='output',name='image',file='STM2.dat', dump=0) 26 | imager.Register("scan.x","scan.y",'STM.Current','inter.F') 27 | 28 | machine.Connect("scan.x","inter.x") 29 | machine.Connect("scan.y","inter.y") 30 | machine.Connect("scan.z","inter.z") 31 | machine.Connect("inter.F","STM.Density") 32 | machine.Connect("scan.record","image.record") 33 | 34 | 35 | machine.circuits['inter'].I['V'].Set(2) 36 | scanner.Place(x=0,y=4,z=15) 37 | 38 | 39 | scanner.Recorder = imager 40 | scanner.BlankLines = True 41 | #resolution of the image [# points per line, # lines] 42 | scanner.Resolution = [200,200] 43 | scanner.ImageArea(18,9) 44 | #scan 45 | scanner.ScanArea() 46 | 47 | if __name__ == '__main__': 48 | main() 49 | -------------------------------------------------------------------------------- /examples/test_STM_ConstantCurrent.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | 4 | def main(): 5 | I = 3e-8 6 | 7 | machine = Machine(machine=None, name='machine', dt=1e-3) 8 | 9 | 10 | 11 | scanner = machine.AddCircuit(type='Scanner',name='scan', pushed=True ) 12 | 13 | machine.AddCircuit(type='PI', name='pi',Kp=-1.1, Ki=-800, set = I, pushed=True) 14 | machine.AddCircuit(type='opAdd', name='Add', pushed=True) 15 | machine.AddCircuit(type='opMul',name='Scaler',in2=10000, pushed=True) 16 | 17 | machine.AddCircuit(type="limiter",name='lim', min=9,max=20, pushed=True) 18 | 19 | inter = machine.AddCircuit(type='i4DlinVasp',name='inter', components=1, pushed=True) 20 | inter.BiasStep=0.5 21 | inter.StartingV=2 22 | inter.ConfigureVASP(pbc=[True,True,False,False]) 23 | inter.ReadVASPData("parchg.2.0") 24 | 25 | 26 | machine.AddCircuit(type='STM',name='STM', pushed=True) 27 | 28 | 29 | out1 = machine.AddCircuit(type='output',name='output',file='testSTM.dat', dump=100) 30 | out1.Register('global.time','scan.x', 'inter.z','Add.out','STM.Current','inter.F','pi.out') 31 | 32 | 33 | imager = machine.AddCircuit(type='output',name='image',file='STM.dat', dump=0) 34 | imager.Register("scan.x","scan.y",'STM.Current','inter.F','pi.out',"inter.z") 35 | 36 | machine.Connect("scan.x","inter.x") 37 | machine.Connect("scan.y","inter.y") 38 | #machine.Connect("scan.z","inter.z") 39 | 40 | 41 | 42 | machine.Connect("pi.out","Scaler.in1") 43 | 44 | machine.Connect("Add.out","lim.signal") 45 | machine.Connect("lim.out","inter.z") 46 | 47 | 48 | 49 | 50 | machine.Connect("inter.F","STM.Density") 51 | machine.Connect("scan.record","image.record") 52 | machine.Connect("STM.Current","pi.signal") 53 | 54 | machine.Connect("scan.z","Add.in1") 55 | machine.Connect("Scaler.out","Add.in2") 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | machine.circuits['inter'].I['V'].Set(2) 65 | scanner.Place(x=0,y=4,z=15) 66 | machine.Wait(2) 67 | 68 | # scanner.Move(x=18,y=0,z=0) 69 | 70 | 71 | ''' 72 | machine.circuits['pi'].I['signal'].Set(1) 73 | machine.Wait(0.1) 74 | machine.circuits['pi'].I['signal'].Set(2) 75 | machine.Wait(0.1) 76 | machine.circuits['pi'].I['signal'].Set(0.1) 77 | machine.Wait(0.1) 78 | ''' 79 | 80 | 81 | scanner.Recorder = imager 82 | scanner.BlankLines = True 83 | FastSpeed = 0.4 84 | #resolution of the image [# points per line, # lines] 85 | scanner.Resolution = [200,200] 86 | scanner.ImageArea(18,9) 87 | #scan 88 | scanner.ScanArea() 89 | 90 | 91 | 92 | if __name__ == '__main__': 93 | main() 94 | -------------------------------------------------------------------------------- /examples/test_SinScan.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | machine = Machine(name='machine', dt=0.001, pushed=True); 7 | 8 | 9 | #Add Circuits 10 | scanner = machine.AddCircuit(type='Scanner',name='scan', pushed=True ) 11 | 12 | 13 | 14 | out1 = machine.AddCircuit(type='output',name='output',file='sintest.dat', dump=1) 15 | out1.Register("global.time","scan.z") 16 | 17 | 18 | scanner.Place(x=1,y=3.5,z=42.5) 19 | scanner.SinScan(amp=2,freq=1,cycles=3) -------------------------------------------------------------------------------- /examples/test_VDW.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | def main(): 7 | 8 | 9 | machine = Machine(name='machine', dt=0.01, pushed=True); 10 | 11 | #Add Circuits 12 | scanner = machine.AddCircuit(type='Scanner',name='scan', pushed=True ) 13 | machine.AddCircuit(type='VDW', name='VDW', alpha=0.28658, hamaker=39.6e-20, radius=3.9487, offset=0, pushed=True) 14 | 15 | 16 | ''' 17 | #xe-ar 18 | #dimer 19 | machine.AddCircuit(type='VDWtorn', name='Dimer',A1=-0.0166279, A2=0.22753, A3=-1819.29, A4=27055.6, A5=-106878., A6=31.8093, tipoffset=0, pushed=True) 20 | 21 | #Surface 22 | machine.AddCircuit(type='VDWtorn', name='Pyramid', A1=-1884.77, A2=619.586, A3=-1391.33, A4=22337., A5=-93389.1, A6=17.5403,tipoffset=0, pushed=True) 23 | 24 | #Pyramid 25 | machine.AddCircuit(type='VDWtorn', name='Surface', A1=-462.061, A2=99.2976, A3=212.33, A4=-682.216, A5=646.31, A6=-7.59327,tipoffset=0, pushed=True) 26 | 27 | 28 | ''' 29 | #xe-Kr 30 | #dimer 31 | machine.AddCircuit(type='VDWtorn', name='Dimer',A1=0.263191, A2=0.527478, A3=-1259.79, A4=23749.8, A5=-88463.2, A6=-4.00773, tipoffset=0, pushed=True) 32 | 33 | #Surface 34 | machine.AddCircuit(type='VDWtorn', name='Pyramid', A1=-1925.32, A2=635.529, A3=-1160.23, A4=22763.2, A5=-101664., A6=1.99542,tipoffset=0, pushed=True) 35 | 36 | #Pyramid 37 | machine.AddCircuit(type='VDWtorn', name='Surface', A1=-891.534, A2=416.779, A3=1558.35, A4=-8353.84, A5=15269.4, A6=-84.7053,tipoffset=0, pushed=True) 38 | 39 | 40 | ''' 41 | #xe-xe 42 | #dimer 43 | machine.AddCircuit(type='VDWtorn', name='Dimer',A1=0.624987, A2=0.42742, A3=1686.2, A4=-12092.2, A5=115496., A6=-115.753, tipoffset=0, pushed=True) 44 | 45 | #Surface 46 | machine.AddCircuit(type='VDWtorn', name='Pyramid',A1=-1987.09, A2=658.103, A3=-587.187, A4=21188.8, A5=-107670., A6=-26.6053,tipoffset=0, pushed=True) 47 | 48 | #Pyramid 49 | machine.AddCircuit(type='VDWtorn', name='Surface', A1=-883.96, A2=412.92, A3=1705.83, A4=-9119.11, A5=16490.2, A6=-87.6929,tipoffset=0, pushed=True) 50 | ''' 51 | 52 | 53 | #debug output 54 | out1 = machine.AddCircuit(type='output',name='output',file='VDW.dat', dump=1) 55 | out1.Register("scan.z","global.time","VDW.fz","Dimer.fz","Surface.fz","Pyramid.fz") 56 | 57 | 58 | machine.Connect("scan.z","VDW.ztip","Dimer.ztip","Surface.ztip","Pyramid.ztip") 59 | 60 | 61 | scanner.Place(x=0,y=0,z=15) 62 | scanner.MoveTo(x=0,y=0,z=4,v=1) 63 | #machine.Wait(10) 64 | 65 | if __name__ == '__main__': 66 | main() 67 | 68 | -------------------------------------------------------------------------------- /examples/test_apll.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmbase import ChannelType 4 | from vafmcircuits import Machine 5 | 6 | import vafmcircuits 7 | #import vafmcircuits_control 8 | #import vafmcircuits_Filters 9 | from customs import * 10 | 11 | 12 | def main(): 13 | 14 | f0=1.0e4 15 | 16 | machine = Machine(name='machine', dt=5.0e-8, pushed=True); 17 | 18 | machine.AddCircuit(type='waver',name='osc', amp=1, freq=f0+4, pushed=True) 19 | machine.AddCircuit(type="Machine",name='pll', assembly=aPLL, filters=[10000,5000,2000], 20 | gain=600.0, f0=f0, Kp=0.5, Ki=800, pushed=True) 21 | 22 | 23 | machine.Connect("osc.cos","pll.signal1") 24 | machine.Connect("pll.sin","pll.signal2") 25 | 26 | 27 | out1 = machine.AddCircuit(type='output',name='output',file='test_apll.log', dump=200) 28 | out1.Register('global.time', 'pll.signal1', 'pll.signal2', 'pll.df') 29 | 30 | machine.Wait(0.01) 31 | machine.circuits['osc'].I['freq'].Set(f0+14) 32 | machine.Wait(0.01) 33 | machine.circuits['osc'].I['freq'].Set(f0-100) 34 | machine.Wait(0.01) 35 | machine.circuits['osc'].I['freq'].Set(f0-300) 36 | machine.Wait(0.01) 37 | 38 | if __name__ == '__main__': 39 | main() 40 | 41 | -------------------------------------------------------------------------------- /examples/test_avg.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | 4 | 5 | def main(): 6 | 7 | machine = Machine(name='machine', dt=0.01, pushed=True); 8 | 9 | #Add Circuits 10 | machine.AddCircuit(type='waver',name='osc', amp=1, freq=1, pushed=True ) 11 | machine.AddCircuit(type='avg', name='avg', time=10, pushed=True) 12 | machine.AddCircuit(type='avg', name='avg2', time=1, moving=True, pushed=True) 13 | 14 | machine.Connect("osc.sin","avg.signal","avg2.signal") 15 | 16 | out1 = machine.AddCircuit(type='output',name='output',file='test_avg.out', dump=2) 17 | out1.Register('global.time', 'osc.sin', 'avg.out','avg2.out') 18 | 19 | machine.Wait(10) 20 | 21 | 22 | if __name__ == '__main__': 23 | main() 24 | 25 | -------------------------------------------------------------------------------- /examples/test_cCore.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmbase import ChannelType 4 | from vafmcircuits import Machine 5 | 6 | import vafmcircuits 7 | import vafmcircuits_Logic 8 | 9 | 10 | def compomaker(compo,**keys): 11 | 12 | compo.AddInput("signal1") 13 | compo.AddInput("signal2") 14 | compo.AddOutput("out") 15 | compo.AddCircuit(type='opAdd',name='adder',factors=2, pushed=True) 16 | compo.Connect("global.signal1","adder.in1") 17 | compo.Connect("global.signal2","adder.in2") 18 | compo.Connect("adder.out","global.out") 19 | 20 | print "ADC assemb led!" 21 | 22 | 23 | def main(): 24 | 25 | 26 | machine = Machine(name='machine', dt=0.01, pushed=True); 27 | 28 | wave = machine.AddCircuit(type='waver',name='wave', amp=1, freq=1, pushed=True ) 29 | adder= machine.AddCircuit(type='opAdd',name='add', pushed=True) 30 | compo= machine.AddCircuit(type='Machine',name='compo', assembly=compomaker, pushed=True) 31 | 32 | outer= machine.AddCircuit(type='output', name='outer', file='test_cCore.log', dump=1 ) 33 | 34 | outer.Register('global.time', 'wave.cos','wave.sin', 'add.out') 35 | 36 | #print wave.cCoreID 37 | #print machine.cCoreID 38 | #machine.cCore.DebugCircuit(machine.cCoreID) 39 | #print wave.cCoreID 40 | #print machine.cCoreO 41 | 42 | machine.cCore.DebugCircuit(wave.cCoreID) 43 | 44 | machine.cCore.DebugCircuit(adder.cCoreID) 45 | machine.Connect('wave.cos','add.in1') 46 | machine.Connect('wave.sin','add.in2') 47 | 48 | machine.cCore.DebugCircuit(adder.cCoreID) 49 | #machine.cCore.DebugCircuit(1) 50 | #machine.cCore.DebugCircuit(2) 51 | 52 | 53 | 54 | 55 | #for i in range(len(wave.I)): 56 | # print i,wave.I.values()[i].signal.cCoreFEED 57 | 58 | machine.Wait(1.03) 59 | 60 | machine.cCore.DebugCircuit(wave.cCoreID) 61 | 62 | """ 63 | #Add Circuits 64 | machine.AddCircuit(type='square',name='s1', amp=1, freq=1, duty=0.5, pushed=True ) 65 | machine.AddCircuit(type='square',name='s2', amp=1, freq=2.5, duty=0.2, pushed=True ) 66 | 67 | machine.AddCircuit(type='NOT',name='not', pushed=True ) 68 | machine.AddCircuit(type='AND',name='and', pushed=True ) 69 | machine.AddCircuit(type='OR',name='or', pushed=True ) 70 | machine.AddCircuit(type='XOR',name='xor', pushed=True ) 71 | machine.AddCircuit(type='NOR',name='nor', pushed=True ) 72 | 73 | machine.Connect("s1.out","not.signal") 74 | machine.Connect("s1.out","and.in1","or.in1","xor.in1","nor.in1") 75 | machine.Connect("s2.out","and.in2","or.in2","xor.in2","nor.in2") 76 | 77 | 78 | out1 = machine.AddCircuit(type='output',name='output',file='test_logic.log', dump=1) 79 | out1.Register('global.time', 's1.out', 's2.out','not.out','and.out','or.out','xor.out','nor.out') 80 | 81 | for i in range(1000): 82 | machine.Update() 83 | """ 84 | 85 | 86 | if __name__ == '__main__': 87 | main() 88 | -------------------------------------------------------------------------------- /examples/test_cantilever.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | from customs_pll import * 5 | 6 | def main(): 7 | 8 | machine = Machine(name='machine', pushed=True, dt = 0.001); 9 | 10 | 11 | #Add Circuits 12 | canti = machine.AddCircuit(type='Cantilever',name='canti', startingz=5, Q=300, k=1, f0=50, pushed=True) 13 | 14 | out1 = machine.AddCircuit(type='output',name='output',file='cantilever.dat', dump=1) 15 | out1.Register("global.time","canti.ztip") 16 | 17 | machine.Wait(2) 18 | 19 | if __name__ == '__main__': 20 | main() 21 | 22 | 23 | -------------------------------------------------------------------------------- /examples/test_comparison.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | def main(): 7 | 8 | #main machine 9 | machine = Machine(name='machine', dt=0.0005, pushed=True); 10 | 11 | # wave generator 12 | machine.AddCircuit(type='waver',name='wave', amp=1, freq=2, pushed=True ) 13 | 14 | machine.AddCircuit(type='Equal', name='eq', pushed=True) 15 | machine.AddCircuit(type='LessOrEqual', name='leq', pushed=True) 16 | machine.AddCircuit(type='GreaterOrEqual', name='geq', pushed=True) 17 | 18 | #connect oscillator to the filters 19 | machine.Connect("wave.cos","eq.in1","leq.in1","geq.in1") 20 | machine.Connect("wave.sin","eq.in2","leq.in2","geq.in2") 21 | 22 | #output to file 23 | out1 = machine.AddCircuit(type='output',name='output',file='test_comparison.out', dump=1) 24 | out1.Register('global.time','wave.cos','wave.sin','eq.out','leq.out','geq.out') 25 | 26 | machine.Wait(1) 27 | 28 | 29 | if __name__ == '__main__': 30 | main() 31 | 32 | -------------------------------------------------------------------------------- /examples/test_delay.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | def main(): 7 | 8 | machine = Machine(name='machine', dt=0.01, pushed=True); 9 | 10 | #Add Circuits 11 | machine.AddCircuit(type='waver',name='osc', amp=1, freq=1, pushed=True ) 12 | machine.AddCircuit(type='delay', name='lag', DelayTime=0.2, pushed=True) 13 | 14 | machine.Connect("osc.sin","lag.signal") 15 | 16 | out1 = machine.AddCircuit(type='output',name='output',file='test_delay.out', dump=1) 17 | out1.Register('global.time', 'osc.sin', 'lag.out') 18 | 19 | machine.Wait(5) 20 | 21 | 22 | if __name__ == '__main__': 23 | main() 24 | 25 | -------------------------------------------------------------------------------- /examples/test_derint.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | def main(): 7 | 8 | machine = Machine(name='machine', dt=0.01, pushed=True); 9 | 10 | #Add Circuits 11 | machine.AddCircuit(type='waver',name='osc', amp=1, freq=1, pushed=True ) 12 | machine.AddCircuit(type='derivative', name='der', pushed=True) 13 | machine.AddCircuit(type='integral', name='int', pushed=True) 14 | 15 | machine.Connect("osc.sin","der.signal","int.signal") 16 | 17 | out1 = machine.AddCircuit(type='output',name='output',file='test_derint.out', dump=2) 18 | out1.Register('global.time', 'osc.sin', 'osc.cos','der.out','int.out') 19 | 20 | machine.Wait(10) 21 | 22 | 23 | if __name__ == '__main__': 24 | main() 25 | 26 | -------------------------------------------------------------------------------- /examples/test_dpfd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | from customs_pll import * 5 | 6 | 7 | def main(): 8 | 9 | f0=1.0e5 10 | 11 | machine = Machine(name='machine', dt=1.0e-8, pushed=True); 12 | 13 | machine.AddCircuit(type='waver',name='osc', amp=1, freq=f0+1.3, pushed=True) 14 | machine.AddCircuit(type='waver',name='vco', amp=1, freq=f0, pushed=True) 15 | machine.AddCircuit(type="Machine",name='pfd', assembly=dPFD, gain=1000.0, fcut=500, 16 | KI=1.0,KP=0.30, pushed=True) 17 | 18 | machine.AddCircuit(type='opAdd',name='frq', in2=f0, pushed=True) 19 | 20 | machine.Connect("osc.cos","pfd.ref") 21 | machine.Connect("vco.cos","pfd.vco") 22 | machine.Connect('pfd.df','frq.in1') 23 | machine.Connect('frq.out','vco.freq') 24 | 25 | out1 = machine.AddCircuit(type='output',name='output',file='test_dpfd.out', dump=100) 26 | out1.Register('global.time', 'pfd.ref', 'pfd.vco', 'pfd.df') 27 | 28 | machine.Wait(0.1) 29 | 30 | 31 | if __name__ == '__main__': 32 | main() 33 | 34 | 35 | -------------------------------------------------------------------------------- /examples/test_events.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmbase import ChannelType 4 | from vafmcircuits import Machine 5 | 6 | import vafmcircuits 7 | import vafmcircuits_Logic 8 | 9 | def andchange(newvalue): 10 | 11 | print "and changed to",newvalue 12 | 13 | def main(): 14 | 15 | 16 | machine = Machine(name='machine', dt=0.01, pushed=True); 17 | 18 | #Add Circuits 19 | machine.AddCircuit(type='square',name='s1', amp=1, freq=1, duty=0.5, pushed=True ) 20 | machine.AddCircuit(type='square',name='s2', amp=1, freq=2.5, duty=0.2, pushed=True ) 21 | 22 | machine.AddCircuit(type='Not',name='not', pushed=True ) 23 | machine.AddCircuit(type='And',name='and', pushed=True ) 24 | machine.AddCircuit(type='OrGate',name='or', pushed=True ) 25 | machine.AddCircuit(type='XOrGate',name='xor', pushed=True ) 26 | machine.AddCircuit(type='NORGate',name='nor', pushed=True ) 27 | 28 | machine.circuits['and'].events['change'] += andchange 29 | 30 | machine.Connect("s1.out","not.signal") 31 | machine.Connect("s1.out","and.in1","or.in1","xor.in1","nor.in1") 32 | machine.Connect("s2.out","and.in2","or.in2","xor.in2","nor.in2") 33 | 34 | 35 | out1 = machine.AddCircuit(type='output',name='output',file='test_logic.log', dump=1) 36 | out1.Register('global.time', 's1.out', 's2.out','not.out','and.out','or.out','xor.out','nor.out') 37 | 38 | for i in range(1000): 39 | machine.Update() 40 | 41 | 42 | 43 | if __name__ == '__main__': 44 | main() 45 | -------------------------------------------------------------------------------- /examples/test_filters.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | def main(): 6 | 7 | #main machine 8 | machine = Machine(name='machine', dt=0.0001, pushed=True); 9 | 10 | # wave generator 11 | machine.AddCircuit(type='waver',name='wave', amp=1, pushed=True ) 12 | 13 | #low-pass filter 14 | machine.AddCircuit(type='SKLP',name='sklp', fcut=100, pushed=True ) 15 | 16 | #amplitude detector for the filter 17 | machine.AddCircuit(type='minmax', name='asklp', CheckTime=0.2, pushed=True) 18 | 19 | #high-pass filter 20 | machine.AddCircuit(type='SKHP',name='skhp', fcut=100, pushed=True ) 21 | #amplitude detector for the filter 22 | machine.AddCircuit(type='minmax', name='askhp', CheckTime=0.2, pushed=True) 23 | #band-pass filter 24 | machine.AddCircuit(type='SKBP',name='skbp', fc=100, band=60, pushed=True ) 25 | #amplitude detector for the filter 26 | machine.AddCircuit(type='minmax', name='askbp', CheckTime=0.2, pushed=True) 27 | 28 | #passive low pass filter 29 | machine.AddCircuit(type='RCLP',name='rclp', fcut=100, order=1, pushed=True ) 30 | #amplitude detector for the filter 31 | machine.AddCircuit(type='minmax', name='arclp', CheckTime=0.2, pushed=True) 32 | 33 | #passive high pass filter 34 | machine.AddCircuit(type='RCHP',name='rchp', fcut=100, order=1, pushed=True ) 35 | #amplitude detector for the filter 36 | machine.AddCircuit(type='minmax', name='archp', CheckTime=0.2, pushed=True) 37 | 38 | #connect oscillator to the filters 39 | machine.Connect("wave.sin","sklp.signal","skhp.signal","skbp.signal","rclp.signal","rchp.signal") 40 | machine.Connect("sklp.out","asklp.signal") #filter -> amplitude detector 41 | machine.Connect("skhp.out","askhp.signal") #filter -> amplitude detector 42 | machine.Connect("skbp.out","askbp.signal") #filter -> amplitude detector 43 | machine.Connect("rclp.out","arclp.signal") #filter -> amplitude detector 44 | machine.Connect("rchp.out","archp.signal") #filter -> amplitude detector 45 | 46 | #output to file - dump=0 means only manual dump 47 | out1 = machine.AddCircuit(type='output',name='output',file='test_filters.out', dump=0) 48 | out1.Register('wave.freq', 'asklp.amp', 'askhp.amp', 'askbp.amp',"arclp.amp","archp.amp") 49 | 50 | 51 | #set the frequency and relax the filter 52 | freq = 5 53 | machine.SetInput(channel="wave.freq", value=freq) 54 | machine.Wait(1) 55 | 56 | while freq < 700: 57 | 58 | #assign the frequency to the oscillator 59 | machine.SetInput(channel="wave.freq", value=freq) 60 | 61 | #wait some time to charge the capacitors in the filters 62 | machine.Wait(0.5) 63 | 64 | out1.Dump() #output to file 65 | freq *= 1.2 #ramp the frequency 66 | 67 | 68 | if __name__ == '__main__': 69 | main() 70 | 71 | -------------------------------------------------------------------------------- /examples/test_filters2.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | 3 | from vafmbase import ChannelType 4 | from vafmcircuits import Machine 5 | 6 | import vafmcircuits 7 | import vafmcircuits_signal_processing 8 | import vafmcircuits_Filters 9 | 10 | def main(): 11 | 12 | #main machine 13 | machine = Machine(name='machine', dt=0.00005, pushed=True); 14 | 15 | # wave generator 16 | machine.AddCircuit(type='waver',name='wave', amp=1, pushed=True ) 17 | 18 | 19 | machine.AddCircuit(type='RCLP',name='sklp', fcut=100, order=1, pushed=True ) 20 | #amplitude detector for the filter 21 | machine.AddCircuit(type='minmax', name='asklp', CheckTime=0.2, pushed=True) 22 | 23 | 24 | machine.AddCircuit(type='RCHP',name='skhp', fcut=100, order=1, pushed=True ) 25 | #amplitude detector for the filter 26 | machine.AddCircuit(type='minmax', name='askhp', CheckTime=0.2, pushed=True) 27 | 28 | 29 | machine.AddCircuit(type='SKBP',name='skbp', fc=100, band=60, pushed=True ) 30 | #amplitude detector for the filter 31 | machine.AddCircuit(type='minmax', name='askbp', CheckTime=0.2, pushed=True) 32 | 33 | #connect oscillator to the filters 34 | machine.Connect("wave.sin","sklp.signal","skhp.signal","skbp.signal") 35 | machine.Connect("sklp.out","asklp.signal") #filter -> amplitude detector 36 | machine.Connect("skhp.out","askhp.signal") #filter -> amplitude detector 37 | machine.Connect("skbp.out","askbp.signal") #filter -> amplitude detector 38 | 39 | #output to file - dump=0 means only manual dump 40 | out1 = machine.AddCircuit(type='output',name='output',file='test_filters2.log', dump=0) 41 | out1.Register('wave.freq', 'asklp.amp', 'askhp.amp', 'askbp.amp') 42 | 43 | 44 | #set the frequency and relax the filter 45 | freq = 5 46 | machine.SetInput(channel="wave.freq", value=freq) 47 | machine.Wait(1) 48 | 49 | while freq < 6000: 50 | 51 | #assign the frequency to the oscillator 52 | machine.SetInput(channel="wave.freq", value=freq) 53 | 54 | #wait some time to charge the capacitors in the filters 55 | machine.Wait(0.5) 56 | 57 | out1.Dump() #output to file 58 | freq *= 1.5 #ramp the frequency 59 | 60 | 61 | 62 | if __name__ == '__main__': 63 | main() 64 | 65 | -------------------------------------------------------------------------------- /examples/test_flipflops.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | def main(): 7 | 8 | #main machine 9 | machine = Machine(name='machine', dt=0.01, pushed=True); 10 | 11 | # wave generator 12 | machine.AddCircuit(type='square',name='a', amp=1, freq=2, offset=0.0, duty=0.1, pushed=True ) 13 | machine.AddCircuit(type='square',name='b', amp=1, freq=1.1, offset=0.0, duty=0.5, pushed=True ) 14 | machine.AddCircuit(type='square',name='clock', amp=0.7, freq=10, offset=0.0, duty=0.5, pushed=True ) 15 | 16 | machine.AddCircuit(type='SRFlipFlop', name='SR', pushed=True) 17 | machine.AddCircuit(type='JKFlipFlop', name='JK', pushed=True) 18 | machine.AddCircuit(type='DFlipFlop', name='D', pushed=True) 19 | machine.AddCircuit(type='DRFlipFlop', name='DR', pushed=True) 20 | 21 | machine.Connect('clock.out','SR.clock','JK.clock','D.clock','DR.clock') 22 | machine.Connect('a.out','JK.J','SR.S','D.D','DR.D') 23 | machine.Connect('b.out','JK.K','SR.R','DR.R') 24 | 25 | #output to file - dump=0 means only manual dump 26 | out1 = machine.AddCircuit(type='output',name='output',file='test_flipflops.out', dump=1) 27 | out1.Register('global.time', 'a.out', 'b.out', 'clock.out', 'SR.Q', 'JK.Q', 'D.Q', 'DR.Q') 28 | 29 | 30 | 31 | machine.Wait(2) 32 | 33 | 34 | if __name__ == '__main__': 35 | main() 36 | -------------------------------------------------------------------------------- /examples/test_i1Dlin.org.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import vafmcircuits 3 | import math 4 | from customs_pll import * 5 | #!/usr/bin/env python 6 | 7 | from vafmbase import ChannelType 8 | from vafmcircuits import Machine 9 | 10 | 11 | 12 | def main(): 13 | 14 | 15 | machine = Machine(name='machine', dt=0.01, pushed=True); 16 | scanner = machine.AddCircuit(type='Scanner',name='scan', pushed=True) 17 | inter = machine.AddCircuit(type='i1Dlin',name='inter', comp=2, step=0.1, pbc=True, pushed=True) 18 | 19 | dump = machine.AddCircuit(type='output',name='output',file='test_i1Dlin.dat', dump=1) 20 | dump.Register('global.time', "scan.x", "inter.F1", "inter.F2") 21 | 22 | machine.Connect("scan.x" , "inter.x") 23 | 24 | #create a forcefield 25 | forces = [[math.sin(2*math.pi*x/20),math.cos(2*2*math.pi*x/20)] for x in range(20)] 26 | inter.SetData(forces) 27 | 28 | #machine.SetInput(channel="output.record", value=0) 29 | #scanner.Place(0,0,500) 30 | #scanner.Move(0,0,-5) 31 | #machine.Wait(0.02) 32 | scanner.Move(x=2,v=1) 33 | 34 | ''' 35 | #machine.SetInput(channel="output.record", value=1) 36 | scanner.Recorder = imager 37 | scanner.BlankLines = True 38 | #resolution of the image [# points per line, # lines] 39 | scanner.Resolution = [30,1] 40 | 41 | scanner.ImageArea(5.64,5.64) 42 | scanner.FastSpeed = 10 43 | scanner.SlowSpeed = 20 44 | scanner.ScanArea() 45 | ''' 46 | 47 | 48 | if __name__ == '__main__': 49 | main() 50 | -------------------------------------------------------------------------------- /examples/test_i1Dlin.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | import math 5 | 6 | def main(): 7 | 8 | machine = Machine(name='machine', dt=0.01, pushed=True); 9 | scanner = machine.AddCircuit(type='Scanner',name='scan', pushed=True) 10 | inter = machine.AddCircuit(type='i1Dlin',name='inter', comp=2, step=0.1, pbc=True, pushed=True) 11 | 12 | dump = machine.AddCircuit(type='output',name='output',file='test_i1Dlin.dat', dump=1) 13 | dump.Register('global.time', "scan.x", "inter.F1", "inter.F2") 14 | 15 | machine.Connect("scan.x" , "inter.x") 16 | 17 | #create a forcefield 18 | forces = [[math.sin(2*math.pi*x/20),math.cos(2*2*math.pi*x/20)] for x in range(20)] 19 | inter.SetData(forces) 20 | 21 | #machine.SetInput(channel="output.record", value=0) 22 | #scanner.Place(0,0,500) 23 | #scanner.Move(0,0,-5) 24 | #machine.Wait(0.02) 25 | scanner.Move(x=2,v=1) 26 | 27 | 28 | if __name__ == '__main__': 29 | main() 30 | -------------------------------------------------------------------------------- /examples/test_i3Dlin.py: -------------------------------------------------------------------------------- 1 | from vafmbase import ChannelType 2 | from vafmcircuits import Machine 3 | import vafmcircuits 4 | 5 | 6 | machine = Machine(machine=None, name='machine', dt=0.01) 7 | scan = machine.AddCircuit(type='Scanner',name='scann') 8 | inter = machine.AddCircuit(type='i3Dlin',name='inter', components=3) 9 | 10 | inter.Configure(steps=[0.705,0.705,0.1], npoints=[8,8,201]) 11 | inter.Configure(pbc=[True,True,False]) 12 | inter.Configure(ForceMultiplier=1e10) 13 | inter.ReadData('NaClforces.dat') 14 | 15 | machine.Connect("scann.x" , "inter.x") 16 | machine.Connect("scann.y" , "inter.y") 17 | machine.Connect("scann.z" , "inter.z") 18 | 19 | 20 | #image output 21 | imager = machine.AddCircuit(type='output',name='image',file='tut2.dat', dump=0) 22 | imager.Register("scann.x", "scann.y", 'inter.F3',"scann.z") 23 | 24 | machine.Connect("scann.record", "image.record") 25 | 26 | scan.Place(x=0, y=0, z=4) 27 | #this will print an empty line after each scanline 28 | scan.Recorder = imager 29 | scan.BlankLines = True 30 | #not necessary, but it makes it easier for gnuplot 31 | 32 | #resolution of the image [# points per line, # lines] 33 | scan.Resolution = [64,64] 34 | scan.ImageArea(11.68,11.68) 35 | 36 | #scan 37 | scan.ScanArea() -------------------------------------------------------------------------------- /examples/test_i4Dlin.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from vafmcircuits import Machine 3 | 4 | def main(): 5 | 6 | machine = Machine(machine=None, name='machine', dt=0.01) 7 | 8 | inter = machine.AddCircuit(type='i4Dlin',name='inter', components=1, pushed=True) 9 | inter.BiasStep=0.5 10 | inter.StartingV=1 11 | inter.ConfigureVASP(pbc=[True,True,False,False]) 12 | inter.ReadVASPData("parchg.1.0") 13 | 14 | scanner = machine.AddCircuit(type='Scanner',name='scan', pushed=True ) 15 | 16 | out1 = machine.AddCircuit(type='output',name='output',file='test4d.dat', dump=1) 17 | out1.Register('scan.x', 'scan.y','scan.z','inter.F1') 18 | 19 | #Imaging output 20 | imager = machine.AddCircuit(type='output',name='image',file='4d.dat', dump=0) 21 | imager.Register("scan.x","scan.y",'inter.F1') 22 | 23 | machine.Connect("scan.x","inter.x") 24 | machine.Connect("scan.y","inter.y") 25 | machine.Connect("scan.z","inter.z") 26 | machine.Connect("scan.record","image.record") 27 | 28 | 29 | machine.circuits['inter'].I['V'].Set(1.0) 30 | scanner.Place(x=0,y=0,z=15) 31 | #scanner.Move(x=16, v=1) 32 | 33 | scanner.Recorder = imager 34 | scanner.BlankLines = True 35 | #resolution of the image [# points per line, # lines] 36 | scanner.Resolution = [50,50] 37 | scanner.ImageArea(18,16) 38 | #scan 39 | scanner.ScanArea() 40 | 41 | if __name__ == '__main__': 42 | main() 43 | -------------------------------------------------------------------------------- /examples/test_interpolation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmbase import ChannelType 4 | from vafmcircuits import Machine 5 | import vafmcircuits 6 | import subprocess 7 | 8 | import vafmcircuits_Filters 9 | import vafmcircuits_Scanner 10 | import vafmcircuits_Cantilever 11 | import vafmcircuits_Interpolation 12 | 13 | 14 | def main(): 15 | 16 | 17 | machine = Machine(machine=None, name='machine', dt=0.001, pushed=False) 18 | 19 | scan = machine.AddCircuit(type='scanner',name='scann', Process = machine, pushed=False) 20 | inter = machine.AddCircuit(type='Interpolate',name='inter', Filename = 'test_interpolation.dat', Dimensions = 3, Components = 3 ,pushed=False) 21 | inter.Minboundary(1,1,30) 22 | inter.Maxboundary(8,8,200) 23 | 24 | machine.Connect("scann.pos" , "inter.coord") 25 | 26 | #Outputs 27 | out1 = machine.AddCircuit(type='output',name='output',file='test_interpolation.log', dump=1) 28 | out1.Register('global.time', 'inter.F1','inter.F2','inter.F3') 29 | 30 | scan.Place(1,1,30) 31 | scan.MoveTo(1,1,40,0.1) 32 | 33 | 34 | if __name__ == '__main__': 35 | main() 36 | -------------------------------------------------------------------------------- /examples/test_limiter.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | def main(): 7 | 8 | machine = Machine(name='machine', dt=0.01, pushed=True); 9 | 10 | #Add the circuits 11 | machine.AddCircuit(type='waver',name='osc', amp=1, freq=1.3, pushed=True ) 12 | machine.AddCircuit(type='limiter', name='lim', max=0.7, min=-0.3, pushed=True) 13 | 14 | machine.Connect("osc.sin","lim.signal") 15 | 16 | out1 = machine.AddCircuit(type='output',name='output',file='test_limiter.out', dump=1) 17 | out1.Register('global.time', "osc.sin","lim.out") 18 | 19 | machine.Wait(5) 20 | 21 | 22 | if __name__ == '__main__': 23 | main() 24 | 25 | -------------------------------------------------------------------------------- /examples/test_logic.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | def main(): 7 | 8 | 9 | machine = Machine(name='machine', dt=0.01, pushed=True); 10 | 11 | #Add Circuits 12 | machine.AddCircuit(type='square',name='s1', amp=1, freq=1, duty=0.5, pushed=True ) 13 | machine.AddCircuit(type='square',name='s2', amp=1, freq=2.5, duty=0.2, pushed=True ) 14 | 15 | machine.AddCircuit(type='NOT',name='not', pushed=True ) 16 | machine.AddCircuit(type='AND',name='and', pushed=True ) 17 | machine.AddCircuit(type='OR',name='or', pushed=True ) 18 | machine.AddCircuit(type='XOR',name='xor', pushed=True ) 19 | machine.AddCircuit(type='NOR',name='nor', pushed=True ) 20 | 21 | machine.Connect("s1.out","not.signal") 22 | machine.Connect("s1.out","and.in1","or.in1","xor.in1","nor.in1") 23 | machine.Connect("s2.out","and.in2","or.in2","xor.in2","nor.in2") 24 | 25 | 26 | out1 = machine.AddCircuit(type='output',name='output',file='test_logic.out', dump=1) 27 | out1.Register('global.time', 's1.out', 's2.out','not.out','and.out','or.out','xor.out','nor.out') 28 | 29 | machine.Wait(10) 30 | 31 | 32 | if __name__ == '__main__': 33 | main() 34 | -------------------------------------------------------------------------------- /examples/test_output.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | def main(): 7 | 8 | 9 | machine = Machine(name='machine', dt=0.01, pushed=True); 10 | 11 | wave = machine.AddCircuit(type='waver',name='wave', amp=1, freq=2, pushed=True ) 12 | outer= machine.AddCircuit(type='output', name='outer', file='test_output.out', dump=0 ) 13 | outer.Register('global.time', 'wave.sin') 14 | 15 | machine.Connect('wave.sin','outer.record') 16 | 17 | machine.Wait(1) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | 23 | -------------------------------------------------------------------------------- /examples/test_peaker.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | def main(): 7 | 8 | machine = Machine(name='machine', dt=0.01, pushed=True); 9 | 10 | #Add Circuits 11 | machine.AddCircuit(type='waver',name='osc', amp=0.2, freq=1.3, pushed=True ) 12 | machine.AddCircuit(type='peaker', name='pkd', up=True, pushed=True) 13 | 14 | machine.Connect("osc.sin","pkd.signal") 15 | 16 | out1 = machine.AddCircuit(type='output',name='output',file='test_peaker.out', dump=1) 17 | out1.Register('global.time', "osc.sin","pkd.tick","pkd.peak","pkd.delay") 18 | 19 | machine.Wait(5) 20 | 21 | 22 | if __name__ == '__main__': 23 | main() 24 | 25 | -------------------------------------------------------------------------------- /examples/test_perlin.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | def main(): 7 | 8 | 9 | machine = Machine(name='machine', dt=0.01, pushed=True); 10 | 11 | machine.AddCircuit(type='Perlin', name='noise', octaves=16, persist=1, amp=0.005, period=0.1, pushed=True) 12 | 13 | #debug output 14 | out1 = machine.AddCircuit(type='output',name='output',file='test_perlin.out', dump=1) 15 | out1.Register("global.time","noise.out") 16 | 17 | machine.Wait(3) 18 | 19 | if __name__ == '__main__': 20 | main() 21 | 22 | 23 | -------------------------------------------------------------------------------- /examples/test_phasor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | def main(): 7 | 8 | 9 | machine = Machine(name='machine', dt=0.01, pushed=True); 10 | 11 | #Add Circuits 12 | machine.AddCircuit(type='waver',name='w1', amp=0.2, freq=1, pushed=True ) 13 | machine.AddCircuit(type='waver',name='w2', amp=0.2, freq=1.15, pushed=True ) 14 | machine.AddCircuit(type='phasor', name='lag', up=True, pushed=True) 15 | 16 | machine.Connect("w1.sin","lag.in1") 17 | machine.Connect("w2.cos","lag.in2") 18 | 19 | out1 = machine.AddCircuit(type='output',name='output',file='test_phasor.out', dump=5) 20 | out1.Register('global.time', "w1.sin","w2.cos","lag.tick","lag.delay") 21 | 22 | machine.Wait(10) 23 | 24 | 25 | if __name__ == '__main__': 26 | main() 27 | 28 | -------------------------------------------------------------------------------- /examples/test_pi.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | def main(): 7 | 8 | machine = Machine(name='machine', dt=0.01, pushed=True); 9 | 10 | machine.AddCircuit(type='waver',name='osc', freq=1, pushed=True) 11 | machine.AddCircuit(type='opAbs',name='abs', pushed=True) 12 | machine.AddCircuit(type='SKLP',name='lp', fc=0.04, pushed=True) 13 | 14 | pi = machine.AddCircuit(type='PI', name='pi', set=2,Kp=0.2,Ki=0) 15 | #pid = machine.AddCircuit(type='PID', name='pi', set=1,Kp=1.5,Ki=0.2,Kd=0.1) 16 | 17 | machine.Connect("osc.sin","abs.signal") 18 | machine.Connect("abs.out","lp.signal") 19 | 20 | machine.Connect("lp.out","pi.signal") 21 | machine.Connect("pi.out","osc.amp") 22 | 23 | out1 = machine.AddCircuit(type='output',name='output',file='test_pi.out', dump=5) 24 | out1.Register('global.time', 'osc.sin', 'lp.out', 'pi.out') 25 | 26 | machine.Wait(100) 27 | 28 | 29 | if __name__ == '__main__': 30 | main() 31 | 32 | -------------------------------------------------------------------------------- /examples/test_pycircuit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | def main(): 7 | 8 | machine = Machine(name='machine', dt=0.01, pushed=True); 9 | 10 | 11 | #Add Circuits 12 | 13 | machine.AddCircuit(type='waver',name='wave', amp=1, freq=1, pushed=True ) 14 | machine.AddCircuit(type='myCirc',name='pytest', pushed=True ) 15 | 16 | machine.Connect("wave.sin","pytest.in1") 17 | machine.Connect("wave.cos","pytest.in2") 18 | 19 | out1 = machine.AddCircuit(type='output',name='output',file='test_pycircuit.out', dump=1) 20 | out1.Register('global.time', 'wave.sin', 'pytest.out') 21 | 22 | machine.Wait(1) 23 | 24 | if __name__ == '__main__': 25 | main() 26 | 27 | -------------------------------------------------------------------------------- /examples/test_rsa.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmbase import ChannelType 4 | from vafmcircuits import Machine 5 | 6 | import vafmcircuits 7 | import vafmcircuits_rsa 8 | from customs_pll import * 9 | 10 | ''' 11 | center of mass position: (x,y,z) = (0, 0, 0.022m) 12 | total mass: 0.0255kg 13 | moment of inertia : 4.62e-6 kgm^2 14 | positions of the springs attached : 15 | (x,y,z) = (-0.0141m, 0, 0.0249m) and (0.0141m, 0, 0.0249m) 16 | ''' 17 | 18 | def main(): 19 | 20 | f0 = 30 21 | 22 | machine = Machine(name='machine', dt=1.0e-5, pushed=True); 23 | 24 | scan= machine.AddCircuit(type='Scanner', name='scan', pushed=True) 25 | exc = machine.AddCircuit(type='waver',name='exc', amp=1, freq=f0, pushed=True) 26 | 27 | rsa = machine.AddCircuit(type='RSA', name='rsa', eta=0.1, pushed=True) 28 | rsa.SetSprings(860,1500000,7000) 29 | rsa.SetPoints(0.0141,0.0029,-0.022) 30 | rsa.SetGammas(0.066, 0.2, 0.1) 31 | rsa.SetMasses(0.0255, 0.06, 4.62e-6) 32 | 33 | machine.AddCircuit(type='Machine', name='amp', assembly=aAMPD, fcut=4, pushed=True) 34 | machine.AddCircuit(type='Machine', name='ampang', assembly=aAMPD, fcut=4, pushed=True) 35 | machine.AddCircuit(type='Machine', name='amplow', assembly=aAMPD, fcut=1, pushed=True) 36 | machine.AddCircuit(type='phasor', name='philow') 37 | machine.AddCircuit(type='phasor', name='phitoplow') 38 | machine.AddCircuit(type='phasor', name='phitop') 39 | machine.AddCircuit(type='phasor', name='phiang') 40 | 41 | machine.Connect("scan.x","exc.freq") 42 | machine.Connect("scan.y","exc.amp") 43 | machine.Connect("scan.z","rsa.eta") 44 | machine.Connect("exc.cos","rsa.exciter") 45 | machine.Connect("rsa.xcm","amp.signal") 46 | 47 | machine.Connect("rsa.x2","amplow.signal") 48 | machine.Connect("rsa.theta","ampang.signal") 49 | machine.Connect("exc.cos","philow.in1") 50 | machine.Connect("rsa.x2","philow.in2") 51 | machine.Connect("rsa.xcm","phitoplow.in1") 52 | machine.Connect("rsa.x2","phitoplow.in2") 53 | machine.Connect("exc.cos","phitop.in1") 54 | machine.Connect("rsa.xcm","phitop.in2") 55 | machine.Connect("exc.cos","phiang.in1") 56 | machine.Connect("rsa.theta","phiang.in2") 57 | 58 | out1 = machine.AddCircuit(type='output',name='output',file='rsa_0.1.out', dump=1) 59 | out1.Register('global.time','exc.cos','rsa.xcm','rsa.x2','rsa.theta') 60 | out1.Stop() 61 | 62 | 63 | scan.Place(x=30,y=1,z=0.0) 64 | machine.Wait(2.0) 65 | 66 | eta=100.1 67 | out2 = machine.AddCircuit(type='output',name='res',file='rsaamp_'+str(eta)+'.out', dump=5000) 68 | out2.Register('exc.freq', 'amp.amp', 'amplow.amp','ampang.amp','philow.delay','phitoplow.delay','phitop.delay','phiang.delay') 69 | #out2.Stop() 70 | 71 | #for eta in [0.0, 0.1, 1.0, 10]: 72 | #for frq in [36,38,40,42,44,46,48,50,52,54,56]: 73 | 74 | scan.Place(x=36,y=1,z=eta) 75 | machine.Wait(5.0) 76 | out2.Start() 77 | scan.MoveTo(x=60, v=0.1) 78 | 79 | 80 | #out1.Start() 81 | #machine.Wait(5.0/frq) 82 | #out1.Stop() 83 | 84 | 85 | 86 | 87 | if __name__ == '__main__': 88 | main() 89 | 90 | -------------------------------------------------------------------------------- /examples/test_scanner.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | def main(): 7 | 8 | 9 | machine = Machine(name='machine', dt=0.001, pushed=True); 10 | 11 | 12 | #Add Circuits 13 | scanner = machine.AddCircuit(type='Scanner',name='scan', pushed=True ) 14 | machine.AddCircuit(type='Perlin', name='nx', octaves=3, persist=0.3, amp=0.05, period=1.23, pushed=True) 15 | machine.AddCircuit(type='Perlin', name='ny', octaves=3, persist=0.3, amp=0.05, period=1.23, pushed=True) 16 | 17 | #create a scalar field 18 | machine.AddCircuit(type='opMul',name='mx', in2=19, pushed=True ) 19 | machine.AddCircuit(type='opMul',name='my', in2=19, pushed=True ) 20 | machine.AddCircuit(type='opSin',name='sinx', pushed=True ) 21 | machine.AddCircuit(type='opSin',name='siny', pushed=True ) 22 | machine.AddCircuit(type='opAdd',name='add', pushed=True ) 23 | 24 | 25 | 26 | #debug output 27 | out1 = machine.AddCircuit(type='output',name='output',file='test_scanner.out', dump=1) 28 | out1.Register('global.time', "scan.x", "scan.y", "scan.z", 'add.out') 29 | 30 | #image output 31 | imager = machine.AddCircuit(type='output',name='image',file='test_scanner_image.out', dump=0) 32 | imager.Register("scan.x", "scan.y", 'add.out') 33 | 34 | machine.Connect("scan.record","image.record") 35 | machine.Connect("scan.x","nx.signal") 36 | machine.Connect("scan.y","ny.signal") 37 | machine.Connect("nx.out","mx.in1") 38 | machine.Connect("ny.out","my.in1") 39 | machine.Connect("mx.out","sinx.signal") 40 | machine.Connect("my.out","siny.signal") 41 | machine.Connect("sinx.out", "add.in1") 42 | machine.Connect("siny.out", "add.in2") 43 | 44 | 45 | 46 | #this will print an empty line after each scanline 47 | scanner.Recorder = imager 48 | scanner.BlankLines = True 49 | #not necessary, but it makes it easier for gnuplot 50 | scanner.FastScan=1 51 | scanner.ImageSize = [2,2] 52 | #resolution of the image [# points per line, # lines] 53 | scanner.Resolution = [64,64] 54 | 55 | #scan 56 | scanner.ScanArea() 57 | 58 | #visualise the image with gnuplot as follows: 59 | #set pm3d map 60 | #set palette rgbformula 34,35,36 61 | #sp'test_scanner_image.log' u 1:2:3 62 | 63 | imager.PlotImage(interpolation='none') 64 | 65 | 66 | if __name__ == '__main__': 67 | main() 68 | 69 | -------------------------------------------------------------------------------- /examples/test_scanner2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | def main(): 7 | 8 | 9 | machine = Machine(name='machine', dt=1e-3, pushed=True); 10 | 11 | #Add Circuits 12 | scanner = machine.AddCircuit(type='Scanner',name='scan', pushed=True ) 13 | 14 | 15 | #debug output 16 | out1 = machine.AddCircuit(type='output',name='output',file='test_scanner.out', dump=0) 17 | out1.Register('global.time', "scan.x", "scan.y", "scan.z") 18 | 19 | #machine.Connect("scan.record","output.record") 20 | 21 | 22 | #scanner.Place(x=1,y=0,z=0) 23 | #scanner.Move(x=1,y=0,z=0,v=1) 24 | #machine.Wait(1) 25 | #scanner.MoveTo(x=3,y=0,z=0,v=1) 26 | #machine.Wait(1) 27 | scanner.MoveRecord(x=2,y=0,z=0,v=1,points=10) 28 | 29 | machine.Wait(1) 30 | if __name__ == '__main__': 31 | main() 32 | 33 | -------------------------------------------------------------------------------- /examples/test_scanner_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SINGROUP/PyVAFM/ac77316fe07818261e3d5c9405d8ccf9ef7508ff/examples/test_scanner_image.png -------------------------------------------------------------------------------- /examples/test_wavers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from vafmcircuits import Machine 4 | 5 | 6 | #main machine 7 | machine = Machine(name='machine', dt=0.0001, pushed=True); 8 | 9 | # wave generator 10 | machine.AddCircuit(type='waver',name='wave', amp=1, freq=2, phi=1, offset=2.0, pushed=True) 11 | machine.AddCircuit(type='square',name='sqw', amp=1.5, freq=2, offset=0.0, duty=0.2, pushed=True ) 12 | 13 | #output to file - dump=0 means only manual dump 14 | out1 = machine.AddCircuit(type='output',name='output',file='test_wavers.out', dump=1) 15 | out1.Register('global.time', 'wave.sin', 'wave.cos', 'wave.saw', 'sqw.out') 16 | 17 | 18 | machine.Wait(1) 19 | -------------------------------------------------------------------------------- /examples/tut2.py: -------------------------------------------------------------------------------- 1 | from vafmbase import ChannelType 2 | from vafmcircuits import Machine 3 | 4 | import vafmcircuits -------------------------------------------------------------------------------- /examples/tutorial_AddCircuits.py: -------------------------------------------------------------------------------- 1 | from vafmcircuits import Machine 2 | 3 | machine = Machine(name='machine', dt=0.01) 4 | 5 | machine.AddCircuit(type='waver', name='osc', freq=1, amp=1) 6 | 7 | machine.AddCircuit(type='TutCircuit', name='TutCircuit',gain=2) 8 | 9 | #machine.Connect('osc.sin','TutCircuit.in') 10 | 11 | logger = machine.AddCircuit(type='output', name='logger', file='tutorial_AddCircuits.out', dump=1) 12 | logger.Register('global.time','osc.sin','TutCircuit.out') 13 | 14 | machine.Wait(1) 15 | -------------------------------------------------------------------------------- /examples/tutorial_basic.py: -------------------------------------------------------------------------------- 1 | from vafmcircuits import Machine 2 | 3 | machine = Machine(name='machine', dt=0.01) 4 | 5 | machine.AddCircuit(type='waver', name='osc', freq=1.2, amp=1) 6 | 7 | machine.AddCircuit(type='opAdd', name='adder', factors=2) 8 | 9 | machine.Connect('osc.sin','adder.in1') 10 | machine.Connect('osc.cos','adder.in2') 11 | 12 | logger = machine.AddCircuit(type='output', name='logger', file='tutorial_basic.out', dump=1) 13 | logger.Register('global.time','osc.sin','osc.cos','adder.out') 14 | 15 | machine.Wait(3) 16 | -------------------------------------------------------------------------------- /examples/vafmcore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SINGROUP/PyVAFM/ac77316fe07818261e3d5c9405d8ccf9ef7508ff/examples/vafmcore.so -------------------------------------------------------------------------------- /mechafm/Makefile: -------------------------------------------------------------------------------- 1 | ## Parameters and files 2 | EXEC = mechafm-mpi 3 | CFILES = mechafm-mpi.c 4 | 5 | ## Compiler 6 | # On local machine 7 | CC = /usr/bin/mpicc 8 | 9 | ## Local directory tree ## 10 | INCDIR = . 11 | 12 | ## Flag settings ## 13 | OPTIM = -O3 -fomit-frame-pointer 14 | MATHFLAG = -lm 15 | WARNFLAG = -Wshadow 16 | FULLFLAG = $(OPTIM) $(WARNFLAG) -I$(INCDIR) 17 | 18 | ## Parallel thingies 19 | MPI_INC = -I/usr/lib/openmpi/include/ 20 | MPI_PATH = -L/usr/lib/openmpi/lib/ 21 | MPI_LIB = 22 | 23 | ## Reshuffle all files ## 24 | FILES = $(CFILES) 25 | 26 | ############################################ 27 | ## Actual make code below (do not change) ## 28 | ############################################ 29 | 30 | ## Make the executable (MPI) ## 31 | $(EXEC): $(FILES) 32 | $(CC) $(FULLFLAG) $(MPI_INC) $(MPI_PATH) $^ $(MATHFLAG) $(MPI_LIB) -o $(EXEC) 33 | mkdir -p bin 34 | mv $(EXEC) bin 35 | 36 | ## Make clean ## 37 | clean: 38 | rm -rf bin/$(EXEC) *~ 39 | 40 | ## Make all ## 41 | all: $(EXEC) -------------------------------------------------------------------------------- /mechafm/boron-gnr-mechafm.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SINGROUP/PyVAFM/ac77316fe07818261e3d5c9405d8ccf9ef7508ff/mechafm/boron-gnr-mechafm.pdf -------------------------------------------------------------------------------- /mechafm/graphene.xyz: -------------------------------------------------------------------------------- 1 | H 7.92740 12.75149 0.00000 0.00000 2 | H 3.53399 12.68727 0.00000 0.00000 3 | H 16.67255 12.67665 0.00000 0.00000 4 | H 5.53581 12.75101 0.00000 0.00000 5 | H 1.13131 12.68307 0.00000 0.00000 6 | H 14.26716 12.67624 0.00000 0.00000 7 | H 1.12949 3.38734 0.00000 0.00000 8 | H 3.53140 3.38275 0.00000 0.00000 9 | H 16.67266 3.39479 0.00000 0.00000 10 | H 7.92550 3.32603 0.00000 0.00000 11 | H 14.26859 3.39437 0.00000 0.00000 12 | H 5.53436 3.32477 0.00000 0.00000 13 | H 12.33297 12.68317 0.00000 0.00000 14 | H 9.93080 12.68984 0.00000 0.00000 15 | H 12.32782 3.38761 0.00000 0.00000 16 | H 9.92587 3.38508 0.00000 0.00000 17 | C 5.26399 8.04086 0.00000 0.00000 18 | C 8.19677 8.03932 0.00000 0.00000 19 | C 6.03190 11.78161 0.00000 0.00000 20 | C 8.19402 10.58274 0.00000 0.00000 21 | C 1.63742 11.71410 0.00000 0.00000 22 | C 3.79321 10.52805 0.00000 0.00000 23 | C 6.01249 9.38029 0.00000 0.00000 24 | C 14.77760 11.71000 0.00000 0.00000 25 | C 16.91155 10.50931 0.00000 0.00000 26 | C 1.60785 9.28164 0.00000 0.00000 27 | C 3.74834 8.03667 0.00000 0.00000 28 | C 14.74566 9.27179 0.00000 0.00000 29 | C 16.92377 8.03553 0.00000 0.00000 30 | C 1.60680 6.78974 0.00000 0.00000 31 | C 7.43170 11.78188 0.00000 0.00000 32 | C 3.02991 11.71601 0.00000 0.00000 33 | C 5.26936 10.57841 0.00000 0.00000 34 | C 7.44731 9.38121 0.00000 0.00000 35 | C 16.16262 11.71041 0.00000 0.00000 36 | C 0.88595 10.51491 0.00000 0.00000 37 | C 3.05372 9.28110 0.00000 0.00000 38 | C 14.02876 10.50776 0.00000 0.00000 39 | C 16.19429 9.27227 0.00000 0.00000 40 | C 0.88615 8.03548 0.00000 0.00000 41 | C 3.05274 6.79054 0.00000 0.00000 42 | C 14.01680 8.03568 0.00000 0.00000 43 | C 16.19484 6.79886 0.00000 0.00000 44 | C 0.88490 5.55790 0.00000 0.00000 45 | C 1.63582 4.35586 0.00000 0.00000 46 | C 14.74630 6.79889 0.00000 0.00000 47 | C 16.91198 5.56362 0.00000 0.00000 48 | C 14.77808 4.36100 0.00000 0.00000 49 | C 6.01200 6.69578 0.00000 0.00000 50 | C 8.19129 5.49924 0.00000 0.00000 51 | C 3.79222 5.54193 0.00000 0.00000 52 | C 6.03018 4.29446 0.00000 0.00000 53 | C 14.02862 5.56184 0.00000 0.00000 54 | C 16.16256 4.36087 0.00000 0.00000 55 | C 7.44942 6.69698 0.00000 0.00000 56 | C 5.26703 5.49426 0.00000 0.00000 57 | C 7.42861 4.29481 0.00000 0.00000 58 | C 3.02844 4.35494 0.00000 0.00000 59 | C 10.43314 11.71751 0.00000 0.00000 60 | C 12.57610 10.51276 0.00000 0.00000 61 | C 10.40786 9.28229 0.00000 0.00000 62 | C 12.57464 8.03607 0.00000 0.00000 63 | C 11.82579 11.71528 0.00000 0.00000 64 | C 9.66866 10.53167 0.00000 0.00000 65 | C 11.85423 9.28198 0.00000 0.00000 66 | C 9.71221 8.03731 0.00000 0.00000 67 | C 11.85265 6.78993 0.00000 0.00000 68 | C 10.40694 6.79186 0.00000 0.00000 69 | C 12.57470 5.55659 0.00000 0.00000 70 | C 10.43010 4.35664 0.00000 0.00000 71 | C 9.66771 5.54525 0.00000 0.00000 72 | C 11.82272 4.35687 0.00000 0.00000 73 | -------------------------------------------------------------------------------- /mechafm/input.scan: -------------------------------------------------------------------------------- 1 | xyzfile graphene.xyz 2 | paramfile parameters.dat 3 | tipatom O 4 | dummyatom X 5 | planeatom C 6 | 7 | minterm f 8 | etol 0.1 9 | ftol 0.1 10 | cfac 0.001 11 | maxsteps 50000 12 | 13 | coulomb on 14 | 15 | zhigh 10.0 16 | zlow 6.0 17 | dx 0.5 18 | dy 0.5 19 | dz 0.1 20 | 21 | bufsize 1000 -------------------------------------------------------------------------------- /mechafm/parameters.dat: -------------------------------------------------------------------------------- 1 | # Parameters for a system from a paper 2 | 3 | # X (A) | Y (A) | Z (A) 4 | box 20.000 15.000 20.000 5 | 6 | # name | epsilon (kcal/mol) | sigma (A) | mass (amu) | charge (e) 7 | atom C 0.07000 3.55000 12.01100 0.00000 8 | atom H 0.03000 2.42000 1.00800 0.00000 9 | atom X 20.00000 3.55000 12.01100 0.02100 10 | atom O 0.19200 3.15000 15.99900 -0.02100 11 | 12 | # name | force constant (kcal/mol) | distance (A) 13 | harm O 0.72000 0.00 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/#Simple dipole test: -------------------------------------------------------------------------------- 1 | #Simple dipole test -------------------------------------------------------------------------------- /src/GausSmear.py: -------------------------------------------------------------------------------- 1 | # Python function to apply Gaussian smearing to data on a regular 3D grid 2 | # Written by M. J. Wolf, Department of Chemistry, Uppsala University 3 | # Finished on 26th Feb 2015 4 | 5 | # real_dir2cart is a 3x3 matrix, the columns of which are the real space lattice vectors 6 | # grid_dim is a 1x3 matrix, the entries of which are the numbers of grid points along each lattice vector 7 | # real_grid_data is the data on the real space grid (3d Vector) 8 | # sigma is the standard deviation of the Gaussian function in real space 9 | 10 | import numpy as np 11 | 12 | 13 | 14 | 15 | def gauss(real_dir2cart, grid_dim, real_grid_data, sigma) : 16 | 17 | cent_point_grid = ( np.floor( np.multiply( np.array( [ 0.5, 0.5, 0.5 ] ), grid_dim ) ) ).astype(int) 18 | 19 | dk = np.linalg.inv( real_dir2cart ).T 20 | 21 | shift_filt_matrix = np.zeros(grid_dim) 22 | 23 | i = np.subtract(np.array(range(0, grid_dim[0])), cent_point_grid[0]) 24 | j = np.subtract(np.array(range(0, grid_dim[1])), cent_point_grid[1]) 25 | k = np.subtract(np.array(range(0, grid_dim[2])), cent_point_grid[2]) 26 | 27 | jj, ii, kk = np.meshgrid(i, j, k) # NOTE STUPID ORDERING OF 3D MESHGRID OUTPUT ! 28 | 29 | xx = np.multiply( ii, dk[0,0]) + np.multiply( jj, dk[0,1]) + np.multiply( kk, dk[0,2]) 30 | yy = np.multiply( ii, dk[1,0]) + np.multiply( jj, dk[1,1]) + np.multiply( kk, dk[1,2]) 31 | zz = np.multiply( ii, dk[2,0]) + np.multiply( jj, dk[2,1]) + np.multiply( kk, dk[2,2]) 32 | 33 | arg = np.multiply( np.multiply(xx,xx) + np.multiply(yy,yy) + np.multiply(zz,zz), -2*np.pi**2*sigma**2 ) 34 | shift_filt_matrix = np.exp(arg) 35 | 36 | filt_matrix = np.fft.ifftshift( shift_filt_matrix ) 37 | 38 | recip_grid_data = np.fft.fftn( real_grid_data ) 39 | 40 | new_real_grid_data = np.fft.ifftn( np.multiply( recip_grid_data, filt_matrix ) ) 41 | 42 | new_real_grid_data = np.multiply( np.sign( np.real( new_real_grid_data ) ) , np.abs( new_real_grid_data ) ) 43 | 44 | return new_real_grid_data -------------------------------------------------------------------------------- /src/cCore/#circuit.h#: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef CIRCUIT 4 | #define CIRCUIT 5 | #define PI 3.14159265358979323846 6 | 7 | // DEFINITION OF CIRCUIT ********************************************** 8 | typedef struct circuit circuit; 9 | 10 | ///Base structure for circuits. 11 | struct circuit { 12 | 13 | //number of inputs and outputs 14 | int nI,nO; 15 | 16 | //indexes of the input, actual and original 17 | int *inputs, *oinputs; 18 | char **inames; 19 | 20 | int *outputs; 21 | 22 | int plen; //number of double parameters 23 | double *params; //array of double parameters 24 | 25 | int iplen; //number of integer parameters 26 | int *iparams; //array of integer parameters 27 | 28 | int vplen; //number of whatever parameters 29 | void **vpparams;//array of whatever parameters lol 30 | 31 | 32 | // for containers 33 | int isContainer; //0|1 34 | int nsubcircs; //number of subcircuits 35 | int *subcircuits; //global indexes of the subcircuits 36 | int *dummyin, *dummyout; //global indexes of dummy input-output circuits 37 | 38 | 39 | //index of the update function 40 | void (*updatef)(circuit*); // 41 | void (*pyupdater)(); 42 | 43 | int init; //index of init function 44 | 45 | int pushed; //0 is false, 1 is true 46 | 47 | }; 48 | //********************************************************************* 49 | //int GlobalChannelCounter = 0; 50 | //int GlobalCircuitCounter = 0; 51 | 52 | //array containing all signals I and O 53 | //double *GlobalSignals; 54 | 55 | 56 | extern double* GlobalSignals; 57 | extern double* GlobalBuffers; 58 | extern int GlobalChannelCounter; 59 | 60 | extern circuit* circuits; 61 | extern int GlobalCircuitCounter; 62 | 63 | extern void (**ufunctions)(circuit*); 64 | extern char **pynames; 65 | 66 | extern double dt; 67 | extern int errorflag; 68 | 69 | int AddToCircuits(circuit c, int containerindex); 70 | int GetCircuitIndex(char* type); 71 | circuit NewCircuit(void); 72 | 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /src/cCore/circuit.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef CIRCUIT 4 | #define CIRCUIT 5 | #define PI 3.14159265358979323846 6 | 7 | // DEFINITION OF CIRCUIT ********************************************** 8 | typedef struct circuit circuit; 9 | 10 | ///Base structure for circuits. 11 | struct circuit { 12 | 13 | //number of inputs and outputs 14 | int nI,nO; 15 | 16 | //indexes of the input, actual and original 17 | int *inputs, *oinputs; 18 | char **inames; 19 | 20 | int *outputs; 21 | 22 | int plen; //number of double parameters 23 | double *params; //array of double parameters 24 | 25 | int iplen; //number of integer parameters 26 | int *iparams; //array of integer parameters 27 | 28 | int vplen; //number of whatever parameters 29 | void **vpparams;//array of whatever parameters lol 30 | 31 | 32 | // for containers 33 | int isContainer; //0|1 34 | int nsubcircs; //number of subcircuits 35 | int *subcircuits; //global indexes of the subcircuits 36 | int *dummyin, *dummyout; //global indexes of dummy input-output circuits 37 | 38 | 39 | //pointer to the update function 40 | void (*updatef)(circuit*); 41 | //pointer to the external update function (in Python) for PyCircuits 42 | void (*pyupdater)(); 43 | 44 | int init; //index of init function 45 | 46 | int pushed; //0 is false, 1 is true 47 | 48 | }; 49 | //********************************************************************* 50 | 51 | 52 | extern double* GlobalSignals; 53 | extern double* GlobalBuffers; 54 | extern int GlobalChannelCounter; 55 | 56 | extern circuit* circuits; 57 | extern int GlobalCircuitCounter; 58 | 59 | extern void (**ufunctions)(circuit*); 60 | extern char **pynames; 61 | 62 | extern double dt; 63 | extern int errorflag; 64 | 65 | int AddToCircuits(circuit c, int containerindex); 66 | int GetCircuitIndex(char* type); 67 | circuit NewCircuit(void); 68 | 69 | 70 | #endif 71 | 72 | -------------------------------------------------------------------------------- /src/cCore/circuit.h~: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef CIRCUIT 4 | #define CIRCUIT 5 | #define PI 3.14159265358979323846 6 | 7 | // DEFINITION OF CIRCUIT ********************************************** 8 | typedef struct circuit circuit; 9 | 10 | ///Base structure for circuits. 11 | struct circuit { 12 | 13 | //number of inputs and outputs 14 | int nI,nO; 15 | 16 | //indexes of the input, actual and original 17 | int *inputs, *oinputs; 18 | char **inames; 19 | 20 | int *outputs; 21 | 22 | int plen; //number of double parameters 23 | double *params; //array of double parameters 24 | 25 | int iplen; //number of integer parameters 26 | int *iparams; //array of integer parameters 27 | 28 | int vplen; //number of whatever parameters 29 | void **vpparams;//array of whatever parameters lol 30 | 31 | 32 | // for containers 33 | int isContainer; //0|1 34 | int nsubcircs; //number of subcircuits 35 | int *subcircuits; //global indexes of the subcircuits 36 | int *dummyin, *dummyout; //global indexes of dummy input-output circuits 37 | 38 | 39 | //pointer to the update function 40 | void (*updatef)(circuit*); 41 | //pointer to the external update function (in Python) for PyCircuits 42 | void (*pyupdater)(); 43 | 44 | int init; //index of init function 45 | 46 | int pushed; //0 is false, 1 is true 47 | 48 | }; 49 | //********************************************************************* 50 | 51 | 52 | extern double* GlobalSignals; 53 | extern double* GlobalBuffers; 54 | extern int GlobalChannelCounter; 55 | 56 | extern circuit* circuits; 57 | extern int GlobalCircuitCounter; 58 | 59 | extern void (**ufunctions)(circuit*); 60 | extern char **pynames; 61 | 62 | extern double dt; 63 | extern int errorflag; 64 | 65 | int AddToCircuits(circuit c, int containerindex); 66 | int GetCircuitIndex(char* type); 67 | circuit NewCircuit(void); 68 | 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/cCore/core_Dipole.c: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CIRCUIT 3 | #include "circuit.h" 4 | #endif 5 | 6 | #ifndef coreDIPOLE 7 | #include "core_Dipole.h" 8 | #endif 9 | 10 | #include 11 | 12 | /*********************************************************************** 13 | c.params[0]=stepz; 14 | c.params[1]=oldV; 15 | c.params[2]=oldForce; 16 | 17 | c.params[3-5] = checks 18 | 19 | * ********************************************************************/ 20 | int Add_Dipole(int owner, double stepz) { 21 | 22 | circuit c = NewCircuit(); 23 | c.nI = 1; 24 | c.nO = 1; 25 | 26 | c.plen = 6; 27 | c.params = (double*)calloc(c.plen,sizeof(double)); 28 | c.params[0]=stepz; 29 | c.params[1]=0; 30 | c.params[2]=0; 31 | c.params[3]=0; 32 | c.params[4]=0; 33 | c.params[5]=0; 34 | 35 | c.updatef = Dipole; 36 | 37 | int index = AddToCircuits(c,owner); 38 | printf("cCore: added Dipole\n"); 39 | return index; 40 | } 41 | 42 | void Dipole( circuit *c ) { 43 | 44 | //printf("%f\n", GlobalSignals[c->inputs[0]] ); 45 | double Force; 46 | if (c->params[3] == 0) 47 | { 48 | //for the first step set the value of Vold for the next step 49 | c->params[1] = GlobalSignals[c->inputs[0]] ; 50 | 51 | } 52 | 53 | 54 | if (c->params[3] == 1) 55 | { 56 | //from the 2nd step onwards calculate the first derivative 57 | //first derivative V - vo / dz 58 | Force = (GlobalSignals[c->inputs[0]] - c->params[1] ) / c->params[0]; 59 | printf("F=%e V=%e Vo=%e\n", Force, GlobalSignals[c->inputs[0]],c->params[1]); 60 | c->params[1]=GlobalSignals[c->inputs[0]]; 61 | GlobalBuffers[c->outputs[0]] = Force; 62 | 63 | 64 | } 65 | 66 | 67 | if (c->params[4] == 0 && c->params[3] == 1) 68 | { 69 | //For only the second step find Old force but make sure this if statement is not executed on the first rust (thats hwy there is params 3 term) 70 | //printf("%f\n",Force ); 71 | c->params[2] = Force; 72 | c->params[4] = 1; 73 | } 74 | 75 | 76 | 77 | if (c->params[5] == 1) 78 | { 79 | //From step 3 onwards calculate 2nd derivative 80 | //2nd derivative F-Fo / dz 81 | GlobalBuffers[c->outputs[0]] = (Force - c->params[2])/c->params[0]; 82 | printf("Out=%e F=%e Fo=%f \n", GlobalBuffers[c->outputs[0]], Force, c->params[2]); 83 | 84 | c->params[2]=Force; 85 | 86 | 87 | } 88 | 89 | if( c->params[3] ==1 ){ c->params[5] = 1; } 90 | 91 | 92 | 93 | 94 | c->params[3] = 1; 95 | 96 | 97 | 98 | 99 | } 100 | 101 | 102 | -------------------------------------------------------------------------------- /src/cCore/core_Dipole.h: -------------------------------------------------------------------------------- 1 | #ifndef coreDIPOLE 2 | #define coreDIPOLE 3 | 4 | 5 | int Add_Dipole(int owner,double stepz); 6 | void Dipole( circuit *c ); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/cCore/core_STM.c: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CIRCUIT 3 | #include "circuit.h" 4 | #endif 5 | 6 | #ifndef coreSTM 7 | #include "core_STM.h" 8 | #endif 9 | 10 | #include 11 | 12 | /*********************************************************************** 13 | c.params[0] = WorkFunction; 14 | c.parmas[1] = WaveFunction Overlap; 15 | c.params[2] = Constant; 16 | * ********************************************************************/ 17 | int Add_STM(int owner, double WorkFunction, double WaveFunctionOverlap) { 18 | 19 | circuit c = NewCircuit(); 20 | c.nI = 1; 21 | c.nO = 1; 22 | 23 | c.plen = 3; 24 | c.params = (double*)calloc(c.plen,sizeof(double)); 25 | c.params[0]=WorkFunction; 26 | c.params[1]=WaveFunctionOverlap; 27 | 28 | c.updatef = STM; 29 | 30 | int index = AddToCircuits(c,owner); 31 | printf("cCore: added STM\n"); 32 | return index; 33 | } 34 | 35 | void STM( circuit *c ) { 36 | 37 | double k = sqrt(2*c->params[0]); 38 | double S = c->params[1]; 39 | 40 | double C = 7.82e-4; 41 | 42 | 43 | double n = GlobalSignals[c->inputs[0]]; 44 | // I = n^2 * k^2 * S^2 * C 45 | GlobalBuffers[c->outputs[0]] = n*n * k*k * S*S * C; 46 | 47 | } 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/cCore/core_STM.h: -------------------------------------------------------------------------------- 1 | #ifndef coreVDW 2 | #define coreVDW 3 | 4 | 5 | int Add_STM(int owner, double WorkFunction, double WaveFunctionOverlap); 6 | void STM( circuit *c ); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/cCore/core_TutCircuit.h: -------------------------------------------------------------------------------- 1 | int Add_TutCircuit(int owner, double gain); 2 | void TutCircuit(circuit *c); 3 | -------------------------------------------------------------------------------- /src/cCore/core_VDW.h: -------------------------------------------------------------------------------- 1 | #ifndef coreVDW 2 | #define coreVDW 3 | 4 | 5 | int Add_VDW(int owner, double alpha, double hamaker, double radius, double offset); 6 | void VDW( circuit *c ); 7 | 8 | int Add_VDWtorn(int owner, double A1, double A2, double A3, double A4, double A5, double A6,double tipoffset ); 9 | void VDWtorn( circuit *c ); 10 | 11 | int Add_LJ(int owner, double ep, double sig); 12 | void LJ( circuit *c ); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/cCore/core_avg.c: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | Averager circuit 3 | *********************************************************/ 4 | 5 | #ifndef CIRCUIT 6 | #include "circuit.h" 7 | #endif 8 | 9 | #ifndef COREAVG 10 | #include "core_avg.h" 11 | #endif 12 | 13 | 14 | int Add_avg(int owner, int nsteps, int moving) { 15 | 16 | circuit c = NewCircuit(); 17 | 18 | c.nI = 1; 19 | c.nO = 1; 20 | 21 | c.iplen = 3; 22 | c.iparams = (int*)calloc(c.plen,sizeof(double)); 23 | 24 | c.iparams[0] = nsteps; 25 | c.iparams[1] = 0; //counter 26 | c.iparams[2] = moving; //moving avg 27 | 28 | c.plen = nsteps+1;//[nsteps] is the total, [0-nsteps-1] is the buffer 29 | c.params = (double*)calloc(c.plen,sizeof(double)); 30 | 31 | c.updatef = avg; 32 | 33 | int index = AddToCircuits(c,owner); 34 | return index; 35 | } 36 | 37 | 38 | void avg(circuit *c) { 39 | 40 | 41 | int nsteps = c->iparams[0]; 42 | int cnt = c->iparams[1]; //counter 43 | 44 | //record the value 45 | c->params[nsteps] -= c->params[cnt]; //remove the value to overwrite from total 46 | c->params[cnt] = GlobalSignals[c->inputs[0]]; //record 47 | 48 | c->params[nsteps] += c->params[cnt]; //add it to the total 49 | 50 | //increment the counter and refit it... 51 | c->iparams[1]++; 52 | if(c->iparams[1] >= nsteps) 53 | c->iparams[1] = 0; 54 | 55 | if (c->iparams[2] == 1) { 56 | //output average 57 | GlobalBuffers[c->outputs[0]] = c->params[nsteps]/nsteps; 58 | } 59 | else { 60 | if(c->iparams[1] == 0) 61 | GlobalBuffers[c->outputs[0]] = c->params[nsteps]/nsteps; 62 | } 63 | 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src/cCore/core_avg.h: -------------------------------------------------------------------------------- 1 | #ifndef COREAVG 2 | #define COREAVG 3 | 4 | 5 | 6 | void avg(circuit *c); 7 | void avg_moving(circuit *c); 8 | 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/cCore/core_cantilever.h: -------------------------------------------------------------------------------- 1 | #ifndef CORECANTILEVER 2 | #define CORECANTILEVER 3 | 4 | int Add_Cantilever(int owner, double Q, double k, double M, double f0, double startingz, double cantiz); 5 | void RunCantilever(circuit *c); 6 | 7 | int Add_AdvancedCantilever(int owner, int numberofmodesV, int numberofmodesL); 8 | void RunAdvancedCantilever(circuit *c); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/cCore/core_comparison.c: -------------------------------------------------------------------------------- 1 | /********************************************************** 2 | Comparison circuits definitions. 3 | *********************************************************/ 4 | 5 | #ifndef CIRCUIT 6 | #include "circuit.h" 7 | #endif 8 | 9 | #ifndef CORECOMPARISON 10 | #include "core_comparison.h" 11 | #endif 12 | 13 | 14 | int CompStart, CompEnd; 15 | //Set names and update functions of comparison operators 16 | void INIT_COMPARISON(int* counter) { 17 | 18 | int i = *counter; CompStart = i; 19 | pynames[i] = "GreaterOrEqual"; ufunctions[i] = GreaterOrEqual; i++; 20 | pynames[i] = "LessOrEqual"; ufunctions[i] = LessOrEqual; i++; 21 | pynames[i] = "Equal"; ufunctions[i] = Equal; i++; 22 | 23 | CompEnd = i-1; 24 | *counter = i; 25 | 26 | } 27 | 28 | int Add_Comparison(int owner, char* type, int ni) { 29 | 30 | circuit c = NewCircuit(); 31 | 32 | c.nI = ni; 33 | c.nO = 1; 34 | 35 | //c.plen = 1; 36 | //c.params = (double*)calloc(c.plen,sizeof(double)); 37 | 38 | int template = GetCircuitIndex(type); 39 | if(template < CompStart || template > CompEnd) { 40 | printf("cERROR! type [%s] is not a Comparison circuit!\n",type); 41 | errorflag++; 42 | } 43 | 44 | c.updatef = ufunctions[template]; 45 | 46 | int index = AddToCircuits(c,owner); 47 | 48 | //printf("Added maths [%s].\n",type); 49 | return index; 50 | 51 | } 52 | 53 | 54 | void GreaterOrEqual( circuit *c ) { 55 | 56 | double result = 0; 57 | if ( GlobalSignals[c->inputs[0]] >= GlobalSignals[c->inputs[1]]){ 58 | result = 1; 59 | } 60 | 61 | 62 | GlobalBuffers[c->outputs[0]] = result; 63 | } 64 | 65 | void LessOrEqual( circuit *c ) { 66 | 67 | double result = 0; 68 | if ( GlobalSignals[c->inputs[0]] <= GlobalSignals[c->inputs[1]]){ 69 | result = 1; 70 | } 71 | 72 | 73 | GlobalBuffers[c->outputs[0]] = result; 74 | } 75 | 76 | void Equal( circuit *c ) { 77 | 78 | double result = 0; 79 | 80 | if ( GlobalSignals[c->inputs[0]] == GlobalSignals[c->inputs[1]]){ 81 | result = 1; 82 | } 83 | //printf("equals: %i %i - %i %lf\n",c->inputs[0],c->inputs[1],c->outputs[0],result); 84 | GlobalBuffers[c->outputs[0]] = result; 85 | } 86 | -------------------------------------------------------------------------------- /src/cCore/core_comparison.h: -------------------------------------------------------------------------------- 1 | #ifndef CORECOMPARISON 2 | #define CORECOMPARISON 3 | 4 | void GreaterOrEqual( circuit *c ); 5 | void LessOrEqual( circuit *c ); 6 | void Equal( circuit *c ); 7 | 8 | 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/cCore/core_container.c: -------------------------------------------------------------------------------- 1 | /********************************************************** 2 | Circuits container definitions. 3 | *********************************************************/ 4 | #include 5 | 6 | #ifndef CIRCUIT 7 | #include "circuit.h" 8 | #endif 9 | 10 | #ifndef CORECONTAINER 11 | #include "core_container.h" 12 | #endif 13 | 14 | 15 | 16 | int Add_Container(int owner, int isMain) { 17 | 18 | printf("cCore: adding container...\n"); 19 | 20 | circuit c = NewCircuit(); 21 | c.isContainer = 1; 22 | 23 | c.dummyin = (int*)calloc(1,sizeof(int)); 24 | c.dummyout = (int*)calloc(1,sizeof(int)); 25 | 26 | c.updatef = (isMain == 1)? ContainerUpdate_Main : ContainerUpdate; 27 | 28 | 29 | int index = AddToCircuits(c,owner); 30 | printf("cCore: added container %i (main:%i)\n",index,isMain); 31 | return index; 32 | 33 | } 34 | 35 | void ExternalRelay( circuit *c ) { 36 | GlobalSignals[c->outputs[0]] = GlobalBuffers[c->outputs[0]] = GlobalSignals[c->inputs[0]]; 37 | } 38 | /*********************************************************************** 39 | * This function creates dummy circuits representing composites external 40 | * channels. 41 | * ********************************************************************/ 42 | int Add_Dummy( int container ) { 43 | 44 | printf("cCore: adding dummy\n"); 45 | 46 | circuit c = NewCircuit(); 47 | 48 | c.nI = 1; 49 | c.nO = 1; 50 | 51 | c.updatef = ExternalRelay; 52 | 53 | int index = AddToCircuits(c, -1); 54 | 55 | //the output is the same as the input 56 | //circuits[index].outputs = circuits[index].inputs; 57 | 58 | 59 | printf("cCore: added dummy %i \n",index); 60 | return index; 61 | 62 | } 63 | 64 | 65 | int Add_ChannelToContainer(int c, int isInput) { 66 | 67 | /* 68 | int chindex = GlobalChannelCounter; 69 | GlobalChannelCounter++; 70 | GlobalSignals = (double*)realloc(GlobalSignals,GlobalChannelCounter*sizeof(double)); 71 | */ 72 | 73 | //allocate a new dummy 74 | int dummyindex = Add_Dummy(-1); //dummy goes in no container, only in global circuits 75 | 76 | //allocate the index slot 77 | if(isInput == 1) { 78 | 79 | circuits[c].nI++; 80 | circuits[c].dummyin = (int*)realloc(circuits[c].dummyin, circuits[c].nI*sizeof(int)); 81 | circuits[c].dummyin[circuits[c].nI-1] = dummyindex; 82 | 83 | } else { 84 | circuits[c].nO++; 85 | circuits[c].dummyout = (int*)realloc(circuits[c].dummyout, circuits[c].nO*sizeof(int)); 86 | circuits[c].dummyout[circuits[c].nO-1] = dummyindex; 87 | } 88 | 89 | 90 | return dummyindex; 91 | } 92 | 93 | /********************************************************* 94 | * Container update function 95 | * ******************************************************/ 96 | void ContainerUpdate(circuit* c) { 97 | 98 | //printf("updating container with %i subcirc\n",c->nsubcircs); 99 | 100 | //relay all external inputs 101 | for (int i = 0; i < c->nI; i++) 102 | { 103 | //the signal of the dummy.out takes the value of the dummy.in 104 | GlobalSignals[circuits[c->dummyin[i]].outputs[0]] = GlobalSignals[circuits[c->dummyin[i]].inputs[0]]; 105 | GlobalBuffers[circuits[c->dummyin[i]].outputs[0]] = GlobalSignals[circuits[c->dummyin[i]].inputs[0]]; 106 | } 107 | 108 | //update subcircuits 109 | for (int i = 0; i < c->nsubcircs; i++) { 110 | //printf(" updating: %i\n",c->subcircuits[i]); 111 | circuits[c->subcircuits[i]].updatef(&(circuits[c->subcircuits[i]])); 112 | //push normal circuits only 113 | if(circuits[c->subcircuits[i]].pushed == 1 && circuits[c->subcircuits[i]].nsubcircs == 0) { 114 | //update signals 115 | //printf(" pushing %i\n",c->subcircuits[i]); 116 | for (int k = 0; k < circuits[c->subcircuits[i]].nO; k++) { 117 | GlobalSignals[circuits[c->subcircuits[i]].outputs[k]] = GlobalBuffers[circuits[c->subcircuits[i]].outputs[k]]; 118 | } 119 | 120 | } 121 | //printf(" done: %i\n",c->subcircuits[i]); 122 | } 123 | 124 | 125 | //relay all external outputs 126 | int idx; 127 | for (int i = 0; i < c->nO; i++) 128 | { 129 | 130 | idx = circuits[c->dummyout[i]].outputs[0]; 131 | GlobalBuffers[idx] = GlobalSignals[circuits[c->dummyout[i]].inputs[0]]; 132 | 133 | //printf("container relay feed of dummy: %d %d -> %lf\n",c->dummyout[i],idx,GlobalBuffers[idx]); 134 | if(c->pushed == 1) 135 | GlobalSignals[idx] = GlobalBuffers[idx]; 136 | 137 | } 138 | 139 | 140 | //printf("done\n"); 141 | 142 | 143 | } 144 | 145 | void ContainerUpdate_Main(circuit* c) { 146 | 147 | //printf("updating cCore time!\n"); 148 | //printf("updating cCore time container with %i subcirc\n",c->nsubcircs); 149 | //printf("container dummy for time: %d %d\n",c->dummyout[0],circuits[c->dummyout[0]].inputs[0]); 150 | //update time 151 | GlobalBuffers[circuits[c->dummyout[0]].inputs[0]] += dt; 152 | GlobalSignals[circuits[c->dummyout[0]].inputs[0]] += dt; 153 | 154 | ContainerUpdate(c); 155 | 156 | //printf("DONE updating cCore time!\n"); 157 | } 158 | 159 | void DoNothing(circuit *c) { 160 | 161 | } 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /src/cCore/core_container.h: -------------------------------------------------------------------------------- 1 | #ifndef CORECONTAINER 2 | #define CORECONTAINER 3 | 4 | //int Add_SKLP( double fcut, double Q, double gain ); 5 | //void SKLP( circuit *c ); 6 | 7 | 8 | int Add_Container(int owner, int isMain); 9 | void ContainerUpdate(circuit* c); 10 | void ContainerUpdate_Main(circuit* c); 11 | void DoNothing(circuit *c); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/cCore/core_container.o-7993e806: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SINGROUP/PyVAFM/ac77316fe07818261e3d5c9405d8ccf9ef7508ff/src/cCore/core_container.o-7993e806 -------------------------------------------------------------------------------- /src/cCore/core_control.c: -------------------------------------------------------------------------------- 1 | /********************************************************** 2 | Control circuits definitions. 3 | *********************************************************/ 4 | 5 | #ifndef CIRCUIT 6 | #include "circuit.h" 7 | #endif 8 | 9 | #ifndef CORECONTROL 10 | #include "core_control.h" 11 | #endif 12 | 13 | 14 | /*********************************************************************** 15 | * Channels: 16 | * inputs[0] = signal 17 | * inputs[1] = set 18 | * inputs[2] = Kp 19 | * inputs[3] = Ki 20 | * outputs[0]= out 21 | * 22 | * Parameters: 23 | * params[0] = accumulated integral part 24 | * params[1] = value of KI*(signal-set) in the previous step 25 | * 26 | * ********************************************************************/ 27 | int Add_PI(int owner) { 28 | 29 | circuit c = NewCircuit(); 30 | c.nI = 4; 31 | c.nO = 1; 32 | 33 | c.plen = 2; 34 | c.params = (double*)calloc(c.plen,sizeof(double)); 35 | 36 | c.updatef = PIC; 37 | 38 | int index = AddToCircuits(c,owner); 39 | printf("cCore: added PI circuit\n"); 40 | return index; 41 | 42 | } 43 | 44 | void PIC( circuit *c ) { 45 | 46 | double delta = GlobalBuffers[c->inputs[1]] - GlobalBuffers[c->inputs[0]]; 47 | 48 | double KI = GlobalSignals[c->inputs[3]]; 49 | //double KP = GlobalSignals[c->inputs[2]]; 50 | 51 | c->params[0] += 0.5*( c->params[1] + KI*delta )*dt; 52 | GlobalBuffers[c->outputs[0]] = delta*GlobalSignals[c->inputs[2]] + c->params[0]; 53 | c->params[1] = KI*delta; 54 | 55 | } 56 | 57 | /*********************************************************************** 58 | * Channels: 59 | * inputs[0] = signal 60 | * inputs[1] = set 61 | * inputs[2] = Kp 62 | * inputs[3] = Ki 63 | * inputs[4] = Kd 64 | * outputs[0]= out 65 | * 66 | * Parameters: 67 | * params[0] = accumulated integral part 68 | * params[1] = value of KI*(signal-set) in the previous step 69 | * params[2] = value of delta in the previous step 70 | * 71 | * ********************************************************************/ 72 | int Add_PID(int owner) { 73 | 74 | circuit c = NewCircuit(); 75 | c.nI = 5; 76 | c.nO = 1; 77 | 78 | c.plen = 3; 79 | c.params = (double*)calloc(c.plen,sizeof(double)); 80 | 81 | c.updatef = PIDC; 82 | 83 | int index = AddToCircuits(c,owner); 84 | printf("cCore: added PID circuit\n"); 85 | return index; 86 | 87 | } 88 | 89 | 90 | void PIDC( circuit *c ) { 91 | 92 | double delta = GlobalBuffers[c->inputs[1]] - GlobalBuffers[c->inputs[0]]; 93 | double KI = GlobalSignals[c->inputs[3]]; 94 | //printf("pid time %lf\n",GlobalSignals[0]); 95 | 96 | c->params[0] += 0.5*( c->params[1] + KI*delta )*dt; 97 | 98 | GlobalBuffers[c->outputs[0]] = delta*GlobalSignals[c->inputs[2]] + 99 | c->params[0] + GlobalSignals[c->inputs[4]]*(delta-c->params[2])/dt; 100 | 101 | c->params[1] = KI*delta; 102 | c->params[2] = delta; 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/cCore/core_control.h: -------------------------------------------------------------------------------- 1 | #ifndef CORECONTROL 2 | #define CORECONTROL 3 | 4 | int Add_PI(int owner ); 5 | int Add_PID(int owner ); 6 | void PIC( circuit *c ); 7 | void PIDC( circuit *c ); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/cCore/core_filters.h: -------------------------------------------------------------------------------- 1 | #ifndef COREFILTERS 2 | #define COREFILTERS 3 | 4 | int Add_SKLP( int owner, double fcut, double Q, double gain ); 5 | void SKLP( circuit *c ); 6 | int Add_SKHP( int owner, double fcut, double Q, double gain ); 7 | void SKHP( circuit *c ); 8 | int Add_SKBP( int owner, double fcut, double band, double gain ); 9 | void SKBP( circuit *c ); 10 | 11 | int add_RCLP( int owner, double fcut, int order); 12 | void RCLP( circuit *c ); 13 | 14 | int add_RCHP( int owner, double fcut, int order); 15 | void RCHP( circuit *c ); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/cCore/core_flipflops.h: -------------------------------------------------------------------------------- 1 | #ifndef COREFLIPFLOP 2 | #define COREFLIPFLOP 3 | 4 | 5 | void DRFlipFlop( circuit *c ); 6 | void JKFlipFlop( circuit *c ); 7 | void DFlipFlop( circuit *c ); 8 | void SRFlipFlop( circuit *c ); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/cCore/core_interpolation.h: -------------------------------------------------------------------------------- 1 | #ifndef COREINTER 2 | #define COREINTER 3 | 4 | int Add_i3Dlin( int owner, int components); 5 | void i3Dlin( circuit *c ); 6 | 7 | void i1Dlin_periodic(circuit* c); 8 | void i1Dlin(circuit* c); 9 | 10 | int Add_i4Dlin( int owner, int components); 11 | void i4Dlin(circuit* c); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/cCore/core_logic.c: -------------------------------------------------------------------------------- 1 | /********************************************************** 2 | Logical circuits definitions. 3 | *********************************************************/ 4 | 5 | #ifndef CIRCUIT 6 | #include "circuit.h" 7 | #endif 8 | 9 | #ifndef CORELOGIC 10 | #include "core_logic.h" 11 | #endif 12 | 13 | 14 | int LogicStart, LogicEnd; 15 | 16 | void INIT_LOGIC(int* counter) { 17 | 18 | int i = *counter; 19 | LogicStart = i; 20 | 21 | pynames[i] = "opAND"; ufunctions[i] = opAND; i++; 22 | pynames[i] = "opNAND"; ufunctions[i] = opNAND; i++; 23 | pynames[i] = "opOR"; ufunctions[i] = opOR; i++; 24 | pynames[i] = "opNOT"; ufunctions[i] = opNOT; i++; 25 | pynames[i] = "opXOR"; ufunctions[i] = opXOR; i++; 26 | pynames[i] = "opNOR"; ufunctions[i] = opNOR; i++; 27 | 28 | LogicEnd = i-1; 29 | *counter = i; 30 | 31 | } 32 | 33 | 34 | int Add_Logic(int owner, char* type, int ni) { 35 | 36 | circuit c = NewCircuit(); 37 | 38 | c.nI = ni; 39 | c.nO = 1; 40 | 41 | int template = GetCircuitIndex(type); 42 | if(template < LogicStart || template > LogicEnd) { 43 | printf("cERROR! type [%s] is not a logic circuit!\n",type); 44 | errorflag++; 45 | } 46 | 47 | c.updatef = ufunctions[template]; 48 | 49 | int index = AddToCircuits(c,owner); 50 | 51 | printf("Added logic [%s].\n",type); 52 | return index; 53 | 54 | } 55 | 56 | 57 | void opAND( circuit *c ) { 58 | 59 | double result = 1; 60 | for(int i=0; i < c->nI; i++){ 61 | if(GlobalSignals[c->inputs[i]] <= 0) { 62 | result = 0; 63 | break; 64 | } 65 | } 66 | GlobalBuffers[c->outputs[0]] = result; 67 | } 68 | 69 | void opNAND( circuit *c ) { 70 | 71 | double result = 1; 72 | 73 | if(GlobalSignals[c->inputs[0]] > 0 && GlobalSignals[c->inputs[1]] > 0) { 74 | result = 0; 75 | } 76 | 77 | GlobalBuffers[c->outputs[0]] = result; 78 | } 79 | 80 | 81 | void opOR( circuit *c ) { 82 | 83 | double result = 0; 84 | for(int i=0; i < c->nI; i++){ 85 | if(GlobalSignals[c->inputs[i]] > 0) { 86 | result = 1; 87 | break; 88 | } 89 | } 90 | GlobalBuffers[c->outputs[0]] = result; 91 | } 92 | 93 | void opNOT( circuit *c ) { 94 | 95 | double result = 1; 96 | if(GlobalSignals[c->inputs[0]] > 0) { 97 | result = 0; 98 | } 99 | 100 | GlobalBuffers[c->outputs[0]] = result; 101 | } 102 | 103 | void opXOR( circuit *c ) { 104 | 105 | double result = 0; 106 | double counter = 0; 107 | 108 | for(int i=0; i < c->nI; i++){ 109 | 110 | if(GlobalSignals[c->inputs[i]] > 0) { 111 | result = 1; 112 | counter = counter +1; 113 | } 114 | } 115 | 116 | if (counter >= 2){ 117 | result = 0; 118 | } 119 | 120 | GlobalBuffers[c->outputs[0]] = result; 121 | } 122 | 123 | void opNOR( circuit *c ) { 124 | 125 | double result = 1; 126 | for(int i=0; i < c->nI; i++){ 127 | if(GlobalSignals[c->inputs[i]] > 0) { 128 | result = 0; 129 | break; 130 | } 131 | } 132 | 133 | GlobalBuffers[c->outputs[0]] = result; 134 | } 135 | 136 | -------------------------------------------------------------------------------- /src/cCore/core_logic.h: -------------------------------------------------------------------------------- 1 | #ifndef CORELOGIC 2 | #define CORELOGIC 3 | 4 | void opAND( circuit *c ); 5 | void opNAND( circuit *c ); 6 | void opOR( circuit *c ); 7 | void opNOT( circuit *c ); 8 | void opXOR( circuit *c ); 9 | void opNOR( circuit *c ); 10 | 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /src/cCore/core_maths.h: -------------------------------------------------------------------------------- 1 | #ifndef COREMATHS 2 | #define COREMATHS 3 | 4 | void opADD( circuit *c ); 5 | void opSUB( circuit *c ); 6 | void opMUL( circuit *c ); 7 | void opDIV( circuit *c ); 8 | void opABS( circuit *c ); 9 | void opPOW( circuit *c ); 10 | void opLINC( circuit *c ); 11 | void opSIN( circuit *c ); 12 | void opCOS( circuit *c ); 13 | 14 | 15 | void perlin( circuit* c ); 16 | void perlin_repopulate(void** array, int oct); 17 | 18 | 19 | void ComplexMagAndPhase(circuit* c); 20 | #endif 21 | -------------------------------------------------------------------------------- /src/cCore/core_output.h: -------------------------------------------------------------------------------- 1 | #ifndef COREOUTPUT 2 | #define COREOUTPUT 3 | 4 | 5 | int Add_output( int owner, char* filename, int dump ); 6 | void output( circuit *c ); 7 | //int output_register (int, int, int); 8 | //int output_register_feed(int outer, int feedid); 9 | int output_close(int outer); 10 | void output_printout( circuit *c ); //this is the function that prints stuff to file 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/cCore/core_pycircuit.c: -------------------------------------------------------------------------------- 1 | /********************************************************** 2 | Python circuits interface 3 | *********************************************************/ 4 | #include 5 | 6 | #ifndef CIRCUIT 7 | #include "circuit.h" 8 | #endif 9 | 10 | #ifndef COREPY 11 | #include "core_pycircuit.h" 12 | #endif 13 | 14 | 15 | int Add_PYCircuit(int* owner, PyObject* self, void (*pyupd)(), int nI, int nO ) { 16 | 17 | 18 | circuit c = NewCircuit(); 19 | c.nI = nI; 20 | c.nO = nO; 21 | 22 | c.plen = 3; 23 | c.params = (double*)calloc(c.plen,sizeof(double)); 24 | 25 | //c.vplen = 2; 26 | //c.vpparams = (void**)malloc(c.vplen*sizeof(PyObject*)); 27 | //c.vpparams[0] = self; //reference to the python object 28 | 29 | c.pyupdater = pyupd; 30 | //printf("PyC init 1 %ld...\n",(c.pyupdater)); 31 | //int* (update)(void) = updfun; 32 | //c.vpparams[1] = updfun; //reference to its update function 33 | //void (*updatef)(circuit*); 34 | 35 | c.updatef = PYUpdate; 36 | 37 | //printf("PyC init 1 %ld...\n",(PyObject*)(c.vpparams[0])); 38 | //printf("PyC init 1 %ld...\n",(PyObject*)(c.vpparams[1])); 39 | 40 | 41 | int index = AddToCircuits(c,owner); 42 | printf("cCore: added PYCircuit\n"); 43 | return index; 44 | } 45 | 46 | void PYUpdate(circuit* c) { 47 | 48 | //printf("cCore: PYCircuit update: %ld...\n",c->pyupdater); 49 | 50 | c->pyupdater(); 51 | //printf("cCore: PYCircuit update returned: %d\n",a); 52 | 53 | 54 | /* 55 | PyObject *func, *res, *test; 56 | printf("PyC update...\n"); 57 | printf("PyC update 1 %ld...\n",(PyObject*)(c->vpparams[0])); 58 | //function getAddress of python object 59 | //func = PyObject_GetAttrString((PyObject*)(c->vpparams[0]), "Update"); 60 | //printf("PyC update 2 %ld...\n",func); 61 | 62 | PyObject_CallMethod((PyObject*)(c->vpparams[0]), "ASD", "()"); 63 | //PyObject_CallFunction(func,NULL); 64 | printf("PyC update 3...\n"); 65 | */ 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/cCore/core_pycircuit.h: -------------------------------------------------------------------------------- 1 | #ifndef COREPY 2 | #define COREPY 3 | 4 | void PYUpdate( circuit* c ); 5 | 6 | #endif 7 | 8 | -------------------------------------------------------------------------------- /src/cCore/core_rsa.c: -------------------------------------------------------------------------------- 1 | /********************************************************** 2 | Resonance Shear Apparatus definitions. 3 | *********************************************************/ 4 | #include 5 | #include 6 | #include 7 | 8 | #ifndef CIRCUIT 9 | #include "circuit.h" 10 | #endif 11 | 12 | #ifndef CORERSA 13 | #include "core_rsa.h" 14 | #endif 15 | 16 | /****************************************************** 17 | * inputs[0] = exciter 18 | * inputs[1] = viscosity 19 | * inputs[2] = friction coeff 20 | * output[0] = xcm 21 | * output[1] = ycm 22 | * output[2] = theta 23 | * output[3] = x2 24 | * params[0-2] = 1/M1, 1/M2, 1/Mrot 25 | * params[3-5] = K1, K1z, K2 26 | * params[6-8] = gamma1, gamma2, gammaRot 27 | * params[9-11] = springx, springy, forcepoint(y) 28 | * params[12-15]= xcm,ycm,angle,x2 29 | * params[16-19]= vxcm,vycm,vangle,vx2 30 | * 31 | * iparams[0] = components 32 | * iparams[1-3] = number of points nx ny nz 33 | * iparams[4] = size of field (1 component) nx*ny*nz 34 | * iparams[5] = size of zy plane (1 component) ny*nz 35 | * iparams[6-8] = periodic 0|1 along each direction 36 | * ***************************************************/ 37 | int Add_RSA( int owner ) { 38 | 39 | //printf("%i \n",xsize); 40 | 41 | circuit c = NewCircuit(); 42 | c.nI = 3; 43 | c.nO = 4; 44 | 45 | /*c.iplen = 9; 46 | c.iparams = (int*)calloc(c.iplen,sizeof(int)); 47 | c.iparams[0] = components;*/ 48 | 49 | c.plen = 20; 50 | c.params = (double*)calloc(c.plen,sizeof(double)); 51 | 52 | c.updatef = RSA; //this is the default scanner update function 53 | int index = AddToCircuits(c,owner); 54 | printf("cCore: RSA initialised\n"); 55 | return index; 56 | 57 | } 58 | 59 | int RSA_SetMasses(int c, double m1, double m2, double mi) { 60 | 61 | circuits[c].params[0] = 1.0/m1; 62 | circuits[c].params[1] = 1.0/m2; 63 | circuits[c].params[2] = 1.0/mi; 64 | 65 | printf("cCore: RSA masses set: %lf %lf %lf \n",circuits[c].params[0], 66 | circuits[c].params[1],circuits[c].params[2]); 67 | 68 | return 0; 69 | } 70 | int RSA_SetSprings(int c, double k1, double k1z, double k2) { 71 | 72 | circuits[c].params[3] = k1; 73 | circuits[c].params[4] = k1z; 74 | circuits[c].params[5] = k2; 75 | printf("cCore: RSA springs set: %lf %lf %lf \n",circuits[c].params[3], 76 | circuits[c].params[4],circuits[c].params[5]); 77 | return 0; 78 | } 79 | int RSA_SetGammas(int c, double g1, double g2, double gr) { 80 | 81 | circuits[c].params[6] = g1; 82 | circuits[c].params[7] = g2; 83 | circuits[c].params[8] = gr; 84 | 85 | printf("cCore: RSA gammas set: %lf %lf %lf \n",circuits[c].params[6], 86 | circuits[c].params[7],circuits[c].params[8]); 87 | 88 | return 0; 89 | } 90 | int RSA_SetPoints(int c, double sx, double sy, double fp) { 91 | 92 | circuits[c].params[ 9] = sx; 93 | circuits[c].params[10] = sy; 94 | circuits[c].params[11] = fp; 95 | 96 | printf("cCore: RSA force points set: %lf %lf %lf \n",circuits[c].params[9], 97 | circuits[c].params[10],circuits[c].params[11]); 98 | 99 | return 0; 100 | } 101 | 102 | void RSA (circuit* c) { 103 | 104 | double eta = GlobalSignals[c->inputs[1]]; 105 | double torq = GlobalSignals[c->inputs[0]]; 106 | 107 | for(int i=0; i<4; i++) 108 | c->params[12+i] += c->params[16+i]*dt; 109 | 110 | // compute forces ************************************************** 111 | double theta = c->params[14]; 112 | //compute the correct position 113 | double x = c->params[9]*cos(theta) - c->params[10]*sin(theta); 114 | double y = c->params[9]*sin(theta) + c->params[10]*cos(theta); 115 | x += c->params[12]; y += c->params[13]; //absolute position of the spring attachement point 116 | 117 | double tmpfx = -c->params[3] * (x - c->params[9]); 118 | double tmpfy = -c->params[4] * (y - c->params[10]); 119 | torq += (x - c->params[12])*tmpfy - (y- c->params[13])*tmpfx; 120 | double forcex = tmpfx, forcey = tmpfy; 121 | //and for the second spring 122 | x = -c->params[9]*cos(theta) - c->params[10]*sin(theta); 123 | y = -c->params[9]*sin(theta) + c->params[10]*cos(theta); 124 | x += c->params[12]; y += c->params[13]; //absolute position of the spring attachement point 125 | 126 | tmpfx = -c->params[3] * (x + c->params[9]); 127 | tmpfy = -c->params[4] * (y - c->params[10]); 128 | torq += (x - c->params[12])*tmpfy - (y- c->params[13])*tmpfx; 129 | forcex += tmpfx; forcey += tmpfy; 130 | 131 | double force2 = -c->params[5] * c->params[15]; //lower spring 132 | 133 | //****************************************************************** 134 | 135 | eta = -eta*(c->params[16] + (-c->params[11])*c->params[18]*cos(theta)-c->params[19]); 136 | forcex += eta; 137 | force2 -= eta; 138 | torq += 0-(c->params[11]*cos(theta)*eta); //torq += 0-(c->params[11]*cos(theta)*mu); 139 | //update speeds 140 | c->params[16] = (c->params[16] + forcex*dt*c->params[0])/(1.0 + c->params[6]*dt*c->params[0]); 141 | c->params[17] = (c->params[17] + forcey*dt*c->params[0])/(1.0 + c->params[6]*dt*c->params[0]); 142 | c->params[18] = (c->params[18] + torq *dt*c->params[2])/(1.0 + c->params[8]*dt*c->params[2]); 143 | c->params[19] = (c->params[19] + force2*dt*c->params[1])/(1.0 + c->params[7]*dt*c->params[1]); 144 | 145 | 146 | GlobalBuffers[c->outputs[0]] = c->params[12]; 147 | GlobalBuffers[c->outputs[1]] = c->params[13]; 148 | GlobalBuffers[c->outputs[2]] = c->params[14]; 149 | GlobalBuffers[c->outputs[3]] = c->params[15]; 150 | 151 | } 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /src/cCore/core_rsa.h: -------------------------------------------------------------------------------- 1 | #ifndef CORERSA 2 | #define CORERSA 3 | 4 | void RSA(circuit* c); 5 | 6 | #endif 7 | 8 | -------------------------------------------------------------------------------- /src/cCore/core_scanner.h: -------------------------------------------------------------------------------- 1 | #ifndef CORESCANNER 2 | #define CORESCANNER 3 | 4 | int Scanner( int owner); 5 | void Scanner_DoIdle( circuit *c ); 6 | unsigned long long int Scanner_Move (int index, double x,double y, double z, double v); 7 | void Scanner_DoMove( circuit *c ); 8 | int Scanner_Place (int index, double x,double y, double z); 9 | void Scanner_DoPlace( circuit *c ); 10 | unsigned long long int Scanner_MoveTo (int index, double x,double y, double z, double v); 11 | void Scanner_DoMoveTo( circuit *c ); 12 | int Scanner_Scan (int index, double x,double y, double z, double v, int points); 13 | void Scanner_DoScan( circuit *c ); 14 | 15 | unsigned long long int SinScan(int index, double freq, double amp,int cycles); 16 | void DoSinScan(circuit *c); 17 | 18 | 19 | unsigned long long int Scanner_Move_Record(int index, double x, double y, double z, double v, int npts); 20 | void Scanner_DoMove_RecordF( circuit *c ); 21 | 22 | int CoordTransform(int owner, double Lvxx,double Lvxy,double Lvxz, double Lvyx,double Lvyy,double Lvyz, double Lvzx,double Lvzy,double Lvzz); 23 | void RunCoordTrans( circuit *c ) ; 24 | 25 | 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/cCore/core_signalprocessing.h: -------------------------------------------------------------------------------- 1 | #ifndef CORESIGNALPROCESSING 2 | #define CORESIGNALPROCESSING 3 | 4 | 5 | void gain( circuit *c ); 6 | void minmax( circuit *c ); 7 | void derivative(circuit *c); 8 | void integral(circuit *c); 9 | void delay(circuit *c); 10 | void peaker(circuit *c); 11 | void phasor(circuit *c); 12 | void limiter(circuit *c); 13 | void flip(circuit *c); 14 | 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/cCore/core_signals.c: -------------------------------------------------------------------------------- 1 | /********************************************************** 2 | Signal generators circuits definitions. 3 | *********************************************************/ 4 | #include 5 | 6 | 7 | #ifndef CIRCUIT 8 | #include "circuit.h" 9 | #endif 10 | 11 | #ifndef CORESIGNALS 12 | #include "core_signals.h" 13 | #define ONEoverTWOPI 0.159154943 14 | 15 | #endif 16 | 17 | /************************************* 18 | in[0]: freq 19 | in[1]: amp 20 | in[2]: phi 21 | in[3]: offset 22 | params[0]: phase 23 | out[0]: sin 24 | out[1]: cos 25 | out[2]: saw 26 | * **********************************/ 27 | int Add_waver(int owner) { 28 | 29 | circuit c = NewCircuit(); 30 | 31 | c.nI = 4; 32 | c.nO = 3; 33 | 34 | 35 | c.plen = 1; 36 | c.params = (double*) calloc(c.plen,sizeof(double)); 37 | 38 | c.updatef = waver; 39 | 40 | 41 | //*** ALLOCATE IN LIST ********************* 42 | int index = AddToCircuits(c,owner); 43 | 44 | printf("cCore: added waver %d\n",index); 45 | 46 | return index; 47 | } 48 | 49 | void waver( circuit *c ) { 50 | 51 | 52 | //printf("waving...\n"); 53 | 54 | c->params[0] += dt*GlobalSignals[c->inputs[0]]; 55 | //c->params[0] -= floor(c->params[0]); 56 | c->params[0] -= (int)(c->params[0]); //this is slightly faster than floor and itz the same for positive numbers! 57 | //printf("waving2...\n"); 58 | 59 | double amp = GlobalSignals[c->inputs[1]]; 60 | double off = GlobalSignals[c->inputs[3]]; 61 | 62 | 63 | double phase = 2*PI*(c->params[0]) + GlobalSignals[c->inputs[2]]; 64 | //printf("waving2... %i %lf\n",c->inputs[2],GlobalSignals[c->inputs[2]]); 65 | GlobalBuffers[c->outputs[0]] = amp*sin(phase) + off; 66 | GlobalBuffers[c->outputs[1]] = amp*cos(phase) + off; 67 | 68 | phase = c->params[0] + ONEoverTWOPI*GlobalSignals[c->inputs[2]]; 69 | phase -= (int)(phase); 70 | GlobalBuffers[c->outputs[2]] = amp*(phase) + off; 71 | //self.O['saw'].value = self.I['amp'].value * (self.machine.time *self.I["freq"].value - math.floor(self.machine.time *self.I["freq"].value)) + self.I['offset'].value 72 | 73 | } 74 | 75 | /************************************* 76 | in[0]: freq 77 | in[1]: amp 78 | in[2]: offset 79 | in[3]: duty 80 | params[0]: phase 81 | out[0]: out 82 | * **********************************/ 83 | int Add_square(int owner) { 84 | 85 | circuit c = NewCircuit(); 86 | 87 | c.nI = 4; 88 | c.nO = 1; 89 | 90 | 91 | c.plen = 1; 92 | c.params = (double*) calloc(c.plen,sizeof(double)); 93 | 94 | c.updatef = square; 95 | 96 | 97 | //*** ALLOCATE IN LIST ********************* 98 | int index = AddToCircuits(c,owner); 99 | 100 | printf("cCore: added square wave %d\n",index); 101 | 102 | return index; 103 | } 104 | void square(circuit *c) { 105 | 106 | c->params[0] += dt*GlobalSignals[c->inputs[0]]; 107 | c->params[0] -= (int)(c->params[0]); 108 | 109 | double out = (c->params[0] < GlobalSignals[c->inputs[3]])? 1.0 : 0.0; 110 | out = out * GlobalSignals[c->inputs[1]] - GlobalSignals[c->inputs[2]]; 111 | GlobalBuffers[c->outputs[0]] = out; 112 | 113 | 114 | } 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /src/cCore/core_signals.h: -------------------------------------------------------------------------------- 1 | #ifndef CORESIGNALS 2 | #define CORESIGNALS 3 | 4 | void waver( circuit *c ); 5 | int Add_waver( int owner ); 6 | 7 | int Add_square( int owner ); 8 | void square(circuit *c); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/cCore/core_tutcirc.c: -------------------------------------------------------------------------------- 1 | 2 | #include "circuit.h" 3 | #include "core_tutcirc.h" 4 | 5 | int Add_TutCirc(int owner, double gain) { 6 | 7 | circuit c = NewCircuit(); 8 | c.nI = 1; 9 | c.nO = 1; 10 | 11 | c.plen = 1; 12 | c.params = (double*)calloc(c.plen,sizeof(double)); 13 | c.params[0]=gain; 14 | 15 | c.updatef = TutCirc; 16 | 17 | int index = AddToCircuits(c,owner); 18 | printf("cCore: added Tutorial Circuit\n"); 19 | return index; 20 | 21 | } 22 | 23 | void TutCirc( circuit *c ) { 24 | double input = GlobalSignals[c->inputs[0]]; 25 | GlobalBuffers[c->outputs[0]] = input * c->params[0]; 26 | 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/cCore/core_tutcirc.h: -------------------------------------------------------------------------------- 1 | 2 | int Add_TutCirc(int owner,double gain); 3 | void TutCirc( circuit *c ); 4 | -------------------------------------------------------------------------------- /src/cCore/main.h: -------------------------------------------------------------------------------- 1 | 2 | //global list of circuits 3 | 4 | 5 | 6 | 7 | /* 8 | int init = 0; 9 | size_t csize = sizeof(circuit); 10 | size_t dsize = sizeof(double); 11 | size_t isize = sizeof(int); 12 | 13 | //int GlobalChannelCounter = 0; 14 | //int GlobalCircuitCounter = 0; 15 | 16 | 17 | //array containing all signals I and O 18 | //double *GlobalSignals; 19 | 20 | 21 | int GlobalNFunctions = 4; 22 | void (**ufunctions)(circuit*); //update functions 23 | void (**ifunctions)(circuit*); //init functions 24 | char **pynames; //python names for the circuits 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | void UpdateCircuit(circuit *c, void (*f)(circuit*)){ 35 | 36 | f(c); 37 | 38 | } 39 | void Update(void){ 40 | 41 | 42 | for(int i=0; i= (step[2])*len(Array[0][0]) - step[2]: 6 | 7 | return 0 8 | 9 | if z < 0: 10 | print "CRASHED INTO SURFACE" 11 | sys.exit() 12 | 13 | #Find pos - pbc 14 | n = [len(Array)-1,len(Array[0])-1,len(Array[0][0])-1] 15 | 16 | #print x,y,z 17 | #+1 here 18 | 19 | # adjust for PBC 20 | x -= math.floor(x/( (n[0])*step[0] )) * (n[0]+1)*step[0] 21 | 22 | y -= math.floor(y/( (n[1])*step[1] )) * (n[1]+1)*step[1] 23 | z -= math.floor(z/( (n[2])*step[2] )) * (n[2]+1)*step[2] 24 | 25 | 26 | #Find voxel indexs 27 | x0 = int ( math.floor(int(round(x/step[0],3)))) 28 | y0 = int ( math.floor(int(round(y/step[1],3)))) 29 | z0 = int ( math.floor(int(round(z/step[2],3)))) 30 | 31 | 32 | ''' 33 | y0 = int (math.floor(y/step[1])) 34 | z0 = int (math.floor(z/step[2])) 35 | ''' 36 | 37 | 38 | 39 | 40 | if x0 == n[0]: 41 | x0 = 0 42 | 43 | if y0 == n[1]: 44 | y0 = 0 45 | 46 | if z0 == n[2]: 47 | z0 = 0 48 | 49 | 50 | 51 | x1 = x0 + 1 52 | y1 = y0 + 1 53 | z1 = z0 + 1 54 | 55 | 56 | 57 | #Find xd,yd,zd 58 | xd = (x - x0*step[0] ) / (x1*step[0] - x0*step[0] ) 59 | yd = (y - y0*step[1] ) / (y1*step[1] - y0*step[1] ) 60 | zd = (z - z0*step[2] ) / (z1*step[2] - z0*step[2] ) 61 | 62 | c00 = Array[x0][y0][z0] * (1-xd) + Array[x1][y0][z0] * xd 63 | c10 = Array[x0][y1][z0] * (1-xd) + Array[x1][y1][z0] * xd 64 | c01 = Array[x0][y0][z1] * (1-xd) + Array[x1][y0][z1] * xd 65 | c11 = Array[x0][y1][z1] * (1-xd) + Array[x1][y1][z1] * xd 66 | 67 | 68 | c0 = c00*(1-yd) + c10*yd 69 | c1 = c01*(1-yd) + c11*yd 70 | 71 | c = c0*(1-zd) + c1*zd 72 | 73 | 74 | 75 | return c 76 | 77 | 78 | #The recipe gives simple implementation of a Discrete Proportional-Integral-Derivative (PID) controller. PID controller gives output value for error between desired reference input and measurement feedback to minimize error value. 79 | #More information: http://en.wikipedia.org/wiki/PID_controller 80 | # 81 | #cnr437@gmail.com 82 | # 83 | ####### Example ######### 84 | # 85 | #p=PID(3.0,0.4,1.2) 86 | #p.setPoint(5.0) 87 | #while True: 88 | # pid = p.update(measurement_value) 89 | # 90 | # 91 | 92 | 93 | class PID: 94 | """ 95 | Discrete PID control 96 | """ 97 | 98 | def __init__(self, P=2.0, I=0.0, D=1.0, Derivator=0, Integrator=0, Integrator_max=500, Integrator_min=-500): 99 | 100 | self.Kp=P 101 | self.Ki=I 102 | self.Kd=D 103 | self.Derivator=Derivator 104 | self.Integrator=Integrator 105 | self.Integrator_max=Integrator_max 106 | self.Integrator_min=Integrator_min 107 | 108 | self.set_point=0.0 109 | self.error=0.0 110 | 111 | def update(self,current_value): 112 | """ 113 | Calculate PID output value for given reference input and feedback 114 | """ 115 | 116 | self.error = self.set_point - current_value 117 | 118 | self.P_value = self.Kp * self.error 119 | self.D_value = self.Kd * ( self.error - self.Derivator) 120 | self.Derivator = self.error 121 | 122 | self.Integrator = self.Integrator + self.error 123 | 124 | if self.Integrator > self.Integrator_max: 125 | self.Integrator = self.Integrator_max 126 | elif self.Integrator < self.Integrator_min: 127 | self.Integrator = self.Integrator_min 128 | 129 | self.I_value = self.Integrator * self.Ki 130 | 131 | PID = self.P_value + self.I_value + self.D_value 132 | 133 | return PID 134 | 135 | def setPoint(self,set_point): 136 | """ 137 | Initilize the setpoint of PID 138 | """ 139 | self.set_point = set_point 140 | self.Integrator=0 141 | self.Derivator=0 142 | 143 | def setIntegrator(self, Integrator): 144 | self.Integrator = Integrator 145 | 146 | def setDerivator(self, Derivator): 147 | self.Derivator = Derivator 148 | 149 | def setKp(self,P): 150 | self.Kp=P 151 | 152 | def setKi(self,I): 153 | self.Ki=I 154 | 155 | def setKd(self,D): 156 | self.Kd=D 157 | 158 | def getPoint(self): 159 | return self.set_point 160 | 161 | def getError(self): 162 | return self.error 163 | 164 | def getIntegrator(self): 165 | return self.Integrator 166 | 167 | def getDerivator(self): 168 | return self.Derivator 169 | -------------------------------------------------------------------------------- /src/vafmcircuits_Comparison.py: -------------------------------------------------------------------------------- 1 | from vafmbase import Circuit 2 | import math 3 | 4 | ## \package vafmcircuits_Comparison 5 | # This file contains the comparison operator circuits. 6 | # 7 | 8 | ## \brief Greater or equal to circuit. 9 | # 10 | # \image html GreaterOrEqual.png "schema" 11 | # Takes two signals in and if signal 1 is greater than or equal to signal 2 then output a 1 12 | # 13 | # \b Initialisation \b parameters: 14 | # - \a pushed True|False 15 | # 16 | # \b Input \b channels: 17 | # - \a in1 = incoming signal 1 18 | # - \a in2 = incoming signal 2 19 | # 20 | # \b Output \b channels: 21 | # - \a out = if \a in1 is \f$ \geq \f$ \a in2 then output 1 22 | # 23 | #\b Examples: 24 | # \code{.py} 25 | # machine.AddCircuit(type='GreaterOrEqual', name='geq', pushed=True) 26 | # \endcode 27 | # 28 | class GreaterOrEqual(Circuit): 29 | 30 | def __init__(self, machine, name, **keys): 31 | 32 | super(self.__class__, self).__init__( machine, name ) 33 | 34 | self.AddInput("in1") 35 | self.AddInput("in2") 36 | 37 | self.AddOutput("out") 38 | 39 | self.cCoreID = Circuit.cCore.Add_Comparison(self.machine.cCoreID,"GreaterOrEqual",2) 40 | 41 | self.SetInputs(**keys) 42 | 43 | def Initialize (self): 44 | 45 | pass 46 | 47 | def Update (self): 48 | pass 49 | 50 | ## \brief Less or equal to circuit. 51 | # 52 | # \image html LessOrEqual.png "schema" 53 | # Takes two signals in and if signal 1 is less than or equal to signal 2 then output a 1 54 | # 55 | # \b Initialisation \b parameters: 56 | # - \a pushed True|False 57 | # 58 | # \b Input \b channels: 59 | # - \a in1 = incoming signal 1 60 | # - \a in2 = incoming signal 2 61 | # 62 | # \b Output \b channels: 63 | # - \a out = if \a in1 is \f$ \leq \f$ \a in2 then output 1 64 | # 65 | #\b Examples: 66 | # \code{.py} 67 | # machine.AddCircuit(type='LessOrEqual', name='leq', pushed=True) 68 | # \endcode 69 | # 70 | class LessOrEqual(Circuit): 71 | 72 | def __init__(self, machine, name, **keys): 73 | 74 | super(self.__class__, self).__init__( machine, name ) 75 | 76 | self.AddInput("in1") 77 | self.AddInput("in2") 78 | 79 | self.AddOutput("out") 80 | 81 | self.cCoreID = Circuit.cCore.Add_Comparison(self.machine.cCoreID,"LessOrEqual",2) 82 | 83 | self.SetInputs(**keys) 84 | 85 | def Initialize (self): 86 | 87 | pass 88 | 89 | def Update (self): 90 | pass 91 | 92 | ## \brief equal to circuit. 93 | # 94 | # \image html Equal.png "schema" 95 | # Takes two signals in and if signal 1 is equal to signal 2 then output a 1 96 | # 97 | # \b Initialisation \b parameters: 98 | # - \a pushed True|False 99 | # 100 | # \b Input \b channels: 101 | # - \a in1 = incoming signal 1 102 | # - \a in2 = incoming signal 2 103 | # 104 | # \b Output \b channels: 105 | # - \a out = if \a in1 \f$ = \f$ \a in2 then output 1 106 | # 107 | #\b Examples: 108 | # \code{.py} 109 | # machine.AddCircuit(type='Equal', name='eq', pushed=True) 110 | # \endcode 111 | # 112 | class Equal(Circuit): 113 | 114 | def __init__(self, machine, name, **keys): 115 | 116 | super(self.__class__, self).__init__( machine, name ) 117 | 118 | self.AddInput("in1") 119 | self.AddInput("in2") 120 | 121 | self.AddOutput("out") 122 | 123 | self.cCoreID = Circuit.cCore.Add_Comparison(self.machine.cCoreID,"Equal",2) 124 | 125 | self.SetInputs(**keys) 126 | 127 | def Initialize (self): 128 | 129 | pass 130 | 131 | def Update (self): 132 | pass 133 | 134 | 135 | -------------------------------------------------------------------------------- /src/vafmcircuits_FlipFlop.py: -------------------------------------------------------------------------------- 1 | from vafmbase import Circuit 2 | import math 3 | 4 | 5 | ## \package vafmcircuits_FlipFlop 6 | # This file contains the flip flop circuits. 7 | # 8 | 9 | 10 | ## \brief SR Flip Flop circuit. 11 | # \image html SRFlipFlop.png "schema" 12 | # 13 | # Truth Table for SR FLip FLop 14 | # 15 | # S |R | Q | QBar | Action 16 | # ------------- | ------------- | ------------- | ------------- | ------------- 17 | # 0 | 0 | Q | Qbar | Hold State 18 | # 0 | 1 | 0 | 1 | Reset 19 | # 1 | 0 | 1 | 0 | Set 20 | # 1 | 1 | X | X | Not Alowed 21 | # 22 | # 23 | # \b Initialisation \b parameters: 24 | # - \a pushed = True|False push the output buffer immediately if True 25 | # 26 | # \b Input \b channels: 27 | # - \a S = set signal 28 | # - \a R = reset signal 29 | # - \a clock = digital clock signal 30 | # 31 | # \b Output \b channels: 32 | # - \a Q = stored bit (0|1) 33 | # - \a Qbar = opposite of the stored bit 34 | # 35 | #\b Examples: 36 | # \code{.py} 37 | # machine.AddCircuit(type='SRFlipFlop', name='sr') 38 | # \endcode 39 | # 40 | class SRFlipFlop(Circuit): 41 | 42 | 43 | def __init__(self, machine, name, **keys): 44 | 45 | super(self.__class__, self).__init__( machine, name ) 46 | 47 | self.AddInput("S") 48 | self.AddInput("R") 49 | self.AddInput("clock") 50 | 51 | self.AddOutput("Q") 52 | self.AddOutput("Qbar") 53 | 54 | self.cCoreID = Circuit.cCore.Add_SRFlipFLop(self.machine.cCoreID) 55 | 56 | 57 | def Initialize (self): 58 | pass 59 | 60 | def Update (self): 61 | pass 62 | 63 | ## \brief JK Flip Flop circuit. 64 | # \image html JKFlipFlop.png 65 | # 66 | # Truth Table JK Flip FLop 67 | # 68 | # J |K | Q | QBar | Action 69 | # ------------- | ------------- | ------------- | ------------- | ------------- 70 | # 0 | 0 | Q | Qbar | Hold State 71 | # 0 | 1 | 0 | 1 | Reset 72 | # 1 | 0 | 1 | 0 | Set 73 | # 1 | 1 | QBar | Q | Toggle 74 | # 75 | # 76 | # \b Initialisation \b parameters: 77 | # - \a pushed = True|False push the output buffer immediately if True 78 | # 79 | # \b Input \b channels: 80 | # - \a J = set signal 81 | # - \a K = reset signal 82 | # - \a clock = digital clock signal 83 | # 84 | # 85 | # \b Output \b channels: 86 | # - \a Q = stored bit (0|1) 87 | # - \a Qbar = opposite of the stored bit 88 | # 89 | #\b Examples: 90 | # \code{.py} 91 | # machine.AddCircuit(type='JKFlipFlop', name='jk') 92 | # \endcode 93 | # 94 | class JKFlipFlop(Circuit): 95 | 96 | 97 | def __init__(self, machine, name, **keys): 98 | 99 | super(self.__class__, self).__init__( machine, name ) 100 | 101 | self.AddInput("J") 102 | self.AddInput("K") 103 | self.AddInput("clock") 104 | 105 | self.AddOutput("Q") 106 | self.AddOutput("Qbar") 107 | 108 | self.cCoreID = Circuit.cCore.Add_JKFlipFLop(self.machine.cCoreID) 109 | 110 | self.SetInputs(**keys) 111 | 112 | 113 | def Initialize (self): 114 | pass 115 | 116 | def Update (self): 117 | pass 118 | 119 | 120 | ## D Flip Flop circuit. 121 | # \image html DFlipFlop.png 122 | # Truth Table D Flip Fop 123 | # 124 | # D | Q | QBar | Action 125 | # ------------- | ------------- | ------------- | ------------- 126 | # 0 | Q | Qbar | No Change 127 | # 1 | 1 | 0 | Set 128 | # 129 | # 130 | # 131 | # \b Initialisation \b parameters: 132 | # - \a pushed = True|False push the output buffer immediately if True 133 | # 134 | # \b Input \b channels: 135 | # - \a D = Data Channel 136 | # - \a clock = digital clock signal 137 | # 138 | # 139 | # \b Output \b channels: 140 | # - \a Q = stored bit (0|1) 141 | # - \a Qbar = opposite of the stored bit 142 | # 143 | #\b Examples: 144 | # \code{.py} 145 | # machine.AddCircuit(type='DFlipFlop', name='D') 146 | # \endcode 147 | # 148 | class DFlipFlop(Circuit): 149 | 150 | 151 | def __init__(self, machine, name, **keys): 152 | 153 | super(self.__class__, self).__init__( machine, name ) 154 | 155 | self.AddInput("D") 156 | self.AddInput("clock") 157 | 158 | self.AddOutput("Q") 159 | self.AddOutput("Qbar") 160 | 161 | self.cCoreID = Circuit.cCore.Add_DFlipFLop(self.machine.cCoreID) 162 | 163 | self.SetInputs(**keys) 164 | 165 | 166 | def Initialize (self): 167 | pass 168 | 169 | def Update (self): 170 | pass 171 | 172 | 173 | ## DR Flip Flop circuit. 174 | # \image html DRFlipFlop.png 175 | # Truth Table DR Flip Flop 176 | # 177 | # D | R | Q | QBar | Action 178 | # ------------- | ------------- | -------------| ------------- | ------------- 179 | # 0 | 0 | Q | Qbar | No Change 180 | # 0 | 1 | 0 | 1 | Reset 181 | # 1 | 0 | 0 | 0 | Set 182 | # 1 | 1 | x | x | Not Alowed 183 | # \b Initialisation \b parameters: 184 | # - \a pushed = True|False push the output buffer immediately if True 185 | # 186 | # \b Input \b channels: 187 | # - \a D = Data Channel 188 | # - \a R = Reset Channel 189 | # - \a clock = digital clock signal 190 | # 191 | # \b Output \b channels: 192 | # - \a Q = stored bit (0|1) 193 | # - \a Qbar = opposite of the stored bit 194 | # 195 | #\b Examples: 196 | # \code{.py} 197 | # machine.AddCircuit(type='DRFlipFlop', name='DR') 198 | # \endcode 199 | # 200 | class DRFlipFlop(Circuit): 201 | 202 | 203 | def __init__(self, machine, name, **keys): 204 | 205 | super(self.__class__, self).__init__( machine, name ) 206 | 207 | self.AddInput("D") 208 | self.AddInput("R") 209 | self.AddInput("clock") 210 | 211 | self.AddOutput("Q") 212 | self.AddOutput("Qbar") 213 | 214 | self.cCoreID = Circuit.cCore.Add_DRFlipFLop(self.machine.cCoreID) 215 | 216 | self.SetInputs(**keys) 217 | 218 | def Initialize (self): 219 | pass 220 | 221 | def Update (self): 222 | pass 223 | 224 | -------------------------------------------------------------------------------- /src/vafmcircuits_STM.py: -------------------------------------------------------------------------------- 1 | from vafmbase import Circuit 2 | import math 3 | import ctypes 4 | 5 | ## \package vafmcircuits_STM 6 | # This file contains the Scanning Tunneling Microscope circuit. 7 | # 8 | 9 | 10 | ## \brief STM circuit. 11 | # 12 | # \image html STM.png "schema" 13 | # Takes in a charge density and outputs current 14 | # 15 | # 16 | # \b Initialisation \b parameters: 17 | # - pushed = True|False push the output buffer immediately if True 18 | # - WorkFunction = float Workfunction of the tip (Default value = 4eV). 19 | # - WaveFunctionOverlap = float Wavefunction overlap of the tip and the sample (Default Value = 2 Angstrom). 20 | # 21 | # \b Input \b channels: 22 | # - \a Density 23 | # 24 | # \b Output \b channels: 25 | # - \a Current = C \Delta S^2 k^2 n^2 26 | # 27 | # 28 | # \b Example: 29 | # \code{.py} 30 | # machine.AddCircuit(type='STM',name='STM', pushed=True) 31 | # \endcode 32 | # 33 | 34 | class STM(Circuit): 35 | 36 | 37 | def __init__(self, machine, name, **keys): 38 | 39 | super(self.__class__, self).__init__( machine, name ) 40 | 41 | if 'WorkFunction' in keys.keys(): 42 | self.WF= keys['WorkFunction'] 43 | else: 44 | print "WARNING: Using default workfunction of 4 eV" 45 | self.WF=4 46 | 47 | if 'WaveFunctionOverlap' in keys.keys(): 48 | self.WaveFunctionOverlap= keys['WaveFunctionOverlap'] 49 | else: 50 | print "WARNING: Using default Wave Function Overlap of 2 Angstrom" 51 | self.WaveFunctionOverlap=2 52 | 53 | 54 | self.cCoreID = Circuit.cCore.Add_STM(machine.cCoreID, ctypes.c_double(self.WF), ctypes.c_double(self.WaveFunctionOverlap) ) 55 | 56 | 57 | self.AddInput("Density") 58 | self.AddOutput("Current") 59 | 60 | self.SetInputs(**keys) 61 | 62 | def Initialize (self): 63 | pass 64 | 65 | 66 | def Update (self): 67 | pass 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/vafmcircuits_TutCircuit.py: -------------------------------------------------------------------------------- 1 | from vafmbase import Circuit 2 | from ctypes import * 3 | 4 | class TutCircuit(Circuit): 5 | #MY VERSION 6 | def __init__(self, machine, name, **keys): 7 | 8 | super(self.__class__, self).__init__( machine, name ) 9 | 10 | gain=1 11 | 12 | if 'gain' in keys.keys(): 13 | gain = float(keys['gain']) 14 | 15 | self.AddInput("in") 16 | self.AddOutput("out") 17 | 18 | self.cCoreID = Circuit.cCore.Add_TutCirc(self.machine.cCoreID,c_double(gain)) 19 | print self.cCoreID 20 | self.SetInputs(**keys) 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/vafmcircuits_VDW.py: -------------------------------------------------------------------------------- 1 | from vafmbase import Circuit 2 | import math 3 | import ctypes 4 | 5 | ## \brief Van Der Waals force circuit. 6 | # \image html VDW.png "schema" 7 | # 8 | # 9 | # 10 | # \b Initialisation \b parameters: 11 | # - \a pushed = True|False push the output buffer immediately if True 12 | # - \a alpha = tip angle 13 | # - \a hamaker = Hamaker constant 14 | # - \a radius = Tip Radius 15 | # - \a offset = tip offset 16 | # 17 | # \b Input \b channels: 18 | # - \a ztip = z posisiton of the tip 19 | # 20 | # \b Output \b channels: 21 | # - \a fz = force 22 | # 23 | #\b Examples: 24 | # \code{.py} 25 | # machine.AddCircuit(type='VDW', name='vdw', alpha=0.28658 ,hamaker=39.6e-20 ,radius=3.9487, offset=0 , pushed=True) 26 | # \endcode 27 | # 28 | class VDW(Circuit): 29 | 30 | 31 | def __init__(self, machine, name, **keys): 32 | 33 | super(self.__class__, self).__init__( machine, name ) 34 | 35 | if 'alpha' in keys.keys(): 36 | alpha = keys['alpha'] 37 | print "alpha = " +str(alpha) 38 | else: 39 | raise NameError("No alpha entered ") 40 | 41 | 42 | if 'hamaker' in keys.keys(): 43 | hamaker = keys['hamaker'] 44 | print "hamaker = " +str(hamaker) 45 | else: 46 | raise NameError("No hamaker entered ") 47 | 48 | 49 | if 'radius' in keys.keys(): 50 | radius = keys['radius'] 51 | print "radius = " +str(radius) 52 | else: 53 | raise NameError("No radius entered ") 54 | 55 | 56 | if 'offset' in keys.keys(): 57 | offset = keys['offset'] 58 | print "offset = " +str(offset) 59 | else: 60 | raise NameError("No offset entered ") 61 | 62 | self.AddInput("ztip") 63 | self.AddOutput("fz") 64 | 65 | Circuit.cCore.Add_VDW.argtypes = [ 66 | ctypes.c_int, #Core Id 67 | ctypes.c_double, #alpha 68 | ctypes.c_double, #hamaker 69 | ctypes.c_double, #radius 70 | ctypes.c_double] #offset 71 | 72 | self.cCoreID = Circuit.cCore.Add_VDW(self.machine.cCoreID,alpha,hamaker,radius,offset) 73 | 74 | self.SetInputs(**keys) 75 | 76 | def Initialize (self): 77 | pass 78 | 79 | 80 | def Update (self): 81 | pass 82 | 83 | 84 | class VDWtorn(Circuit): 85 | 86 | 87 | def __init__(self, machine, name, **keys): 88 | 89 | super(self.__class__, self).__init__( machine, name ) 90 | 91 | 92 | if 'A1' in keys.keys(): 93 | A1 = keys['A1'] 94 | print "A1 = " +str(A1) 95 | else: 96 | raise NameError("No A1 entered ") 97 | 98 | if 'A2' in keys.keys(): 99 | A2 = keys['A2'] 100 | print "A2 = " +str(A2) 101 | else: 102 | raise NameError("No A2 entered ") 103 | 104 | if 'A3' in keys.keys(): 105 | A3 = keys['A3'] 106 | print "A3 = " +str(A3) 107 | else: 108 | raise NameError("No A3 entered ") 109 | 110 | if 'A4' in keys.keys(): 111 | A4 = keys['A4'] 112 | print "A4 = " +str(A4) 113 | else: 114 | raise NameError("No A4 entered ") 115 | 116 | if 'A5' in keys.keys(): 117 | A5 = keys['A5'] 118 | print "A5 = " +str(A5) 119 | else: 120 | raise NameError("No A5 entered ") 121 | 122 | if 'A6' in keys.keys(): 123 | A6 = keys['A6'] 124 | print "A6 = " +str(A6) 125 | else: 126 | A6=0 127 | 128 | if 'tipoffset' in keys.keys(): 129 | tipoffset = keys['tipoffset'] 130 | print "tipoffset = " +str(tipoffset) 131 | else: 132 | raise NameError("No tipoffset entered ") 133 | 134 | 135 | self.AddInput("ztip") 136 | self.AddOutput("fz") 137 | self.AddOutput("debug1") 138 | self.AddOutput("debug2") 139 | 140 | Circuit.cCore.Add_VDWtorn.argtypes = [ 141 | ctypes.c_int, #Core Id 142 | ctypes.c_double, #A1 143 | ctypes.c_double, #A2 144 | ctypes.c_double, #A3 145 | ctypes.c_double, #A4 146 | ctypes.c_double, #A5 147 | ctypes.c_double, #A6 148 | ctypes.c_double] #tipoffset 149 | 150 | 151 | self.cCoreID = Circuit.cCore.Add_VDWtorn(self.machine.cCoreID,A1,A2,A3,A4,A5,A6,tipoffset) 152 | 153 | self.SetInputs(**keys) 154 | 155 | def Initialize (self): 156 | pass 157 | 158 | 159 | def Update (self): 160 | pass 161 | 162 | 163 | 164 | 165 | ## \brief Lennard Jones Potential circuit. 166 | # \image html LJ.png "schema" 167 | # 168 | # Produces a Lennard Jones potentinal with given paramaters 169 | # 170 | # \b Initialisation \b parameters: 171 | # - \a pushed = True|False push the output buffer immediately if True 172 | # - \a epsilon = epsilon of the Lennard Jones potential 173 | # - \a sigma = Sigma of the Lennard Jones potential 174 | # 175 | # \b Input \b channels: 176 | # - \a ztip = z posisiton of the tip 177 | # 178 | # \b Output \b channels: 179 | # - \a F = Total Potential Output 180 | # - \a Repulsive = Just the repuslive part of the Potential 181 | # - \a Attractive = Just the attractive part of the Potential 182 | # 183 | #\b Examples: 184 | # \code{.py} 185 | # machine.AddCircuit(type='LJ', name='lj',epsilon=3.9487, sigma=1 , pushed=True) 186 | # \endcode 187 | # 188 | 189 | 190 | 191 | class LJ(Circuit): 192 | 193 | 194 | def __init__(self, machine, name, **keys): 195 | 196 | super(self.__class__, self).__init__( machine, name ) 197 | 198 | if 'epsilon' in keys.keys(): 199 | ep = keys['epsilon'] 200 | else: 201 | raise NameError("No epsilon entered ") 202 | 203 | 204 | if 'sigma' in keys.keys(): 205 | sig = keys['sigma'] 206 | else: 207 | raise NameError("No sigma entered ") 208 | 209 | 210 | self.AddInput("ztip") 211 | 212 | self.AddOutput("F") 213 | self.AddOutput("Repulsive") 214 | self.AddOutput("Attractive") 215 | 216 | 217 | Circuit.cCore.Add_LJ.argtypes = [ 218 | ctypes.c_int, #owner 219 | ctypes.c_double, #ep 220 | ctypes.c_double] #sig 221 | 222 | self.cCoreID = Circuit.cCore.Add_LJ(self.machine.cCoreID,ep,sig) 223 | 224 | self.SetInputs(**keys) 225 | 226 | 227 | def Initialize (self): 228 | pass 229 | 230 | 231 | def Update (self): 232 | pass -------------------------------------------------------------------------------- /src/vafmcircuits_avg.py: -------------------------------------------------------------------------------- 1 | from vafmbase import Circuit 2 | from vafmbase import ChannelType 3 | from vafmbase import Channel 4 | from ctypes import c_int 5 | 6 | import math 7 | import numpy 8 | 9 | ## \package vafmcircuits_avg 10 | # This file contains the averager circuit classes. 11 | 12 | ## \brief Averager circuit. 13 | # 14 | # \image html Avg.png "schema" 15 | # This circuit will return the average of an input signal, over a certain amount of time. 16 | # 17 | # \b Initialisation \b parameters: 18 | # - \a pushed = True|False push the output buffer immediately if True 19 | # - \a time = sampling time (in real time units) 20 | # - \a moving = True|False compute average at each step (True) or only when the buffer is full (False, default) 21 | # 22 | # \b Input \b channels: 23 | # - \a signal = signal to average 24 | # 25 | # \b Output \b channels: 26 | # - \a out = averaged signal 27 | # 28 | #\b Examples: 29 | # \code{.py} 30 | # machine.AddCircuit(type='avg', name='average', time = 10, moving = False , pushed = 'True') 31 | # \endcode 32 | # 33 | class avg(Circuit): 34 | 35 | 36 | def __init__(self, machine, name, **keys): 37 | 38 | super(self.__class__, self).__init__( machine, name ) 39 | 40 | self.AddInput("signal") 41 | self.AddOutput("out") 42 | 43 | self._time = 0.01 44 | self._steps = 10 45 | self._cnt = 0 46 | self._moving = False 47 | 48 | if 'time' in keys.keys(): 49 | self._time = float(keys['time']) 50 | else: 51 | raise NameError("Missing time parameter!") 52 | 53 | self._steps = math.floor(self._time/self.machine.dt) 54 | self._buffer = numpy.zeros(self._steps) 55 | 56 | if 'moving' in keys.keys(): 57 | self._moving = bool(keys['moving']) 58 | 59 | m = c_int(0); 60 | if(self._moving == True): 61 | m = c_int(1) 62 | 63 | self.cCoreID = Circuit.cCore.Add_avg(machine.cCoreID, int(self._steps), m) 64 | 65 | 66 | self.SetInputs(**keys) 67 | 68 | self.tot = 0 69 | 70 | def Initialize (self): 71 | 72 | pass 73 | 74 | 75 | def Update (self): 76 | pass 77 | 78 | 79 | -------------------------------------------------------------------------------- /src/vafmcircuits_control.py: -------------------------------------------------------------------------------- 1 | from vafmbase import Circuit 2 | from vafmbase import ChannelType 3 | from vafmbase import Channel 4 | 5 | import math 6 | 7 | 8 | ## \package vafmcircuits_control 9 | # This file contains the controller circuits. 10 | # 11 | 12 | ## \brief PI circuit. 13 | # 14 | # \image html PI.png "schema" 15 | # This circuit will compare the input signal with a reference signal and 16 | # regulate the output in order to minimise the difference using a PI controller. 17 | # 18 | # \b Initialisation \b parameters: 19 | # - \a pushed = True|False push the output buffer immediately if True 20 | # 21 | # \b Input \b channels: 22 | # - \a signal = incoming signal 23 | # - \a set = reference signal 24 | # - \a Kp = proportional constant 25 | # - \a Ki = integral constant 26 | # 27 | # \b Output \b channels: 28 | # - \a out = \f$ K_p (set-signal) + K_i \int (set-signal) dt \f$ 29 | # 30 | #\b Examples: 31 | # \code{.py} 32 | # machine.AddCircuit(type='PI', name='pi') 33 | # machine.AddCircuit(type='PI', name='pi', Kp=0.1) 34 | # machine.AddCircuit(type='PI', name='pi', Kp=0.2, Ki=0.01) 35 | # \endcode 36 | # 37 | class PI(Circuit): 38 | 39 | 40 | def __init__(self, machine, name, **keys): 41 | 42 | super(self.__class__, self).__init__( machine, name ) 43 | 44 | self.AddInput("signal") 45 | self.AddInput("set") 46 | self.AddInput("Kp") 47 | self.AddInput("Ki") 48 | 49 | 50 | self.AddOutput("out") 51 | 52 | self.cCoreID = Circuit.cCore.Add_PI(machine.cCoreID) 53 | 54 | self.SetInputs(**keys) 55 | 56 | def Initialize (self): 57 | 58 | pass 59 | 60 | 61 | 62 | def Update (self): 63 | pass 64 | 65 | 66 | ## \brief PID circuit. 67 | # 68 | # \image html PID.png "schema" 69 | # This circuit will compare the input signal with a reference signal and 70 | # regulate the output in order to minimise the difference using a PID controller. 71 | # 72 | # \b Initialisation \b parameters: 73 | # - \a pushed = True|False push the output buffer immediately if True 74 | # 75 | # \b Input \b channels: 76 | # - \a signal = incoming signal 77 | # - \a set = reference signal 78 | # - \a Kp = proportional constant 79 | # - \a Ki = integral constant 80 | # - \a Kd = derivative constant 81 | # 82 | # \b Output \b channels: 83 | # - out = \f$ K_p (set-signal) + K_i \int (set-signal) dt +K_d\frac{d(set-signal)}{dt}\f$ 84 | # 85 | #\b Examples: 86 | # \code{.py} 87 | # machine.AddCircuit(type='PID', name='pid') 88 | # machine.AddCircuit(type='PID', name='pid', Kp=0.1) 89 | # machine.AddCircuit(type='PID', name='pid', Kp=0.2, Ki=0.01, Kd=0.1) 90 | # \endcode 91 | # 92 | class PID(Circuit): 93 | 94 | 95 | def __init__(self, machine, name, **keys): 96 | 97 | super(self.__class__, self).__init__( machine, name ) 98 | 99 | self.AddInput("signal") 100 | self.AddInput("set") 101 | self.AddInput("Kp") 102 | self.AddInput("Ki") 103 | self.AddInput("Kd") 104 | self.AddOutput("out") 105 | 106 | self.cCoreID = Circuit.cCore.Add_PID(machine.cCoreID) 107 | 108 | self.SetInputs(**keys) 109 | 110 | def Initialize (self): 111 | pass 112 | 113 | 114 | 115 | 116 | def Update (self): 117 | pass 118 | 119 | -------------------------------------------------------------------------------- /src/vafmcircuits_pycirc.py: -------------------------------------------------------------------------------- 1 | from vafmbase import Circuit 2 | from vafmbase import ChannelType 3 | from vafmbase import Channel 4 | import ctypes as c 5 | 6 | import math 7 | 8 | ## \package vafmcircuits_pycirc.py 9 | # This file contains the controller circuits. 10 | # 11 | 12 | 13 | class PYCircuit(Circuit): 14 | 15 | 16 | def __init__(self, machine, name, **keys): 17 | #print "PY: initing PYCircuit!" 18 | 19 | super(PYCircuit, self).__init__( machine, name ) 20 | 21 | 22 | def Create(self, **keys): 23 | 24 | #create the callback function 25 | CBFunc = c.CFUNCTYPE(None) 26 | self.callback = CBFunc(self.Update) 27 | 28 | self.cCoreID = Circuit.cCore.Add_PYCircuit(self.machine.cCoreID, (c.py_object(self)), 29 | self.callback, len(self.I),len(self.O)) 30 | 31 | self.SetInputs(**keys) 32 | 33 | def Initialize (self): 34 | pass 35 | 36 | 37 | 38 | class myCirc(PYCircuit): 39 | 40 | def __init__(self, machine, name, **keys): 41 | 42 | super(self.__class__, self).__init__( machine, name ) 43 | 44 | self.AddInput("in1") 45 | self.AddInput("in2") 46 | self.AddOutput("out") 47 | 48 | 49 | self.Create(**keys) 50 | 51 | 52 | def Update(self): 53 | 54 | self.O["out"].value = self.I["in1"].value*self.I["in2"].value 55 | 56 | -------------------------------------------------------------------------------- /src/vafmcircuits_rsa.py: -------------------------------------------------------------------------------- 1 | ## \package vafmcircuits_control.py 2 | # This file contains the controller circuits. 3 | # 4 | 5 | from vafmbase import Circuit 6 | from vafmbase import ChannelType 7 | from vafmbase import Channel 8 | from ctypes import * 9 | 10 | import math 11 | 12 | class RSA(Circuit): 13 | 14 | 15 | def __init__(self, machine, name, **keys): 16 | 17 | super(self.__class__, self).__init__( machine, name ) 18 | 19 | self.AddInput("exciter") 20 | self.AddInput("eta") 21 | self.AddInput("mu") 22 | 23 | self.AddOutput("xcm") 24 | self.AddOutput("ycm") 25 | self.AddOutput("theta") 26 | self.AddOutput("x2") 27 | 28 | Circuit.cCore.RSA_SetMasses.argtypes = [c_int, c_double, c_double, c_double] 29 | Circuit.cCore.RSA_SetGammas.argtypes = [c_int, c_double, c_double, c_double] 30 | Circuit.cCore.RSA_SetPoints.argtypes = [c_int, c_double, c_double, c_double] 31 | Circuit.cCore.RSA_SetSprings.argtypes = [c_int, c_double, c_double, c_double] 32 | 33 | self.cCoreID = Circuit.cCore.Add_RSA(machine.cCoreID) 34 | 35 | self.masses = [1,1,1] 36 | if "masses" in keys.keys(): 37 | self.masses = keys["masses"] 38 | self._SetMasses() 39 | 40 | self.springs = [1,1,1] 41 | if "springs" in keys.keys(): 42 | self.springs = keys["springs"] 43 | self._SetSprings() 44 | 45 | self.gammas = [0.1,0.1,0.1] 46 | if "gammas" in keys.keys(): 47 | self.gammas = keys["gammas"] 48 | self._SetGammas() 49 | 50 | self.points = [1,1,-1] 51 | if "points" in keys.keys(): 52 | self.points = keys["points"] 53 | self._SetPoints() 54 | 55 | self.SetInputs(**keys) 56 | 57 | 58 | def Initialize (self): 59 | 60 | pass 61 | 62 | def _SetSprings(self): 63 | Circuit.cCore.RSA_SetSprings(self.cCoreID, self.springs[0], self.springs[1], self.springs[2]) 64 | def SetSprings(self, k1,k1z,k2): 65 | self.springs = [k1,k1z,k2] 66 | self._SetSprings() 67 | 68 | def _SetPoints(self): 69 | Circuit.cCore.RSA_SetPoints(self.cCoreID, self.points[0], self.points[1], self.points[2]) 70 | def SetPoints(self,springx,springy,forcep): 71 | self.points = [springx,springy,forcep] 72 | self._SetPoints() 73 | 74 | def _SetGammas(self): 75 | Circuit.cCore.RSA_SetGammas(self.cCoreID, self.gammas[0], self.gammas[1], self.gammas[2]) 76 | def SetGammas(self,g1,g2,grot): 77 | self.gammas = [g1,g2,grot] 78 | self._SetGammas() 79 | 80 | def _SetMasses(self): 81 | Circuit.cCore.RSA_SetMasses(self.cCoreID, self.masses[0], self.masses[1], self.masses[2]) 82 | def SetMasses(self,m1,m2,mi): 83 | self.masses = [m1,m2,mi] 84 | self._SetMasses() 85 | 86 | def Update (self): 87 | pass 88 | 89 | -------------------------------------------------------------------------------- /src/vafmcircuits_signal_gens.py: -------------------------------------------------------------------------------- 1 | from collections import OrderedDict 2 | from vafmbase import Circuit 3 | from vafmbase import ChannelType 4 | from vafmbase import Channel 5 | import math 6 | 7 | 8 | ## \package vafmcircuits_signal_gens 9 | # This module contains signal generator circuits (automatically imported). 10 | 11 | 12 | ## \brief Oscillator circuit. 13 | # 14 | # \image html waver.png "schema" 15 | # Creates sine and cosine waves with the specifics given by the inputs. 16 | # Can also create a sawtooth wave and a linear increasing signal (Ramper) 17 | # 18 | # \b Initialisation \b parameters: 19 | # - pushed = True|False push the output buffer immediately if True 20 | # 21 | # \b Input \b channels: 22 | # - \a amp = amplitude 23 | # - \a freq = frequency 24 | # - \a offset = offset value 25 | # 26 | # \b Output \b channels: 27 | # - \a sin = \f$amp\cdot \sin(2 \pi freq\cdot t) + offset \f$ sine wave 28 | # - \a cos = \f$amp\cdot \cos(2 \pi freq\cdot t) + offset \f$ cosine wave 29 | # - \a saw = \f$amp\cdot( freq*f(t) - floor(freq*f(t) ) + offset \f$ sawtooth wave 30 | # 31 | # 32 | # \b Example: 33 | # \code{.py} 34 | # machine.AddCircuit(type='waver', name='wgen') 35 | # machine.AddCircuit(type='waver', name='wgen', amp=1.2, freq=12000) 36 | # \endcode 37 | # 38 | class waver(Circuit): 39 | 40 | 41 | def __init__(self, machine, name, **keys): 42 | 43 | super(self.__class__, self).__init__( machine, name ) 44 | 45 | self.AddInput("freq") 46 | self.AddInput("amp") 47 | self.AddInput("phi") 48 | self.AddInput("offset") 49 | 50 | 51 | self.AddOutput("sin") 52 | self.AddOutput("cos") 53 | self.AddOutput("saw") 54 | 55 | self.cCoreID = self.machine.cCore.Add_waver(self.machine.cCoreID) 56 | 57 | self.SetInputs(**keys) 58 | 59 | 60 | self.phase = 0 61 | 62 | def Initialize (self): 63 | 64 | pass 65 | 66 | 67 | 68 | 69 | def Update (self): 70 | pass 71 | 72 | 73 | ## Digital square wave generator circuit. 74 | # 75 | # \image html square.png "schema" 76 | # Creates sine and cosine waves with the specifics given by the inputs. 77 | # Can also create a sawtooth wave and a linear increasing signal (Ramper) 78 | # 79 | # \b Initialisation \b parameters: 80 | # - \a pushed = True|False push the output buffer immediately if True 81 | # 82 | # \b Input \b channels: 83 | # - \a amp amplitude 84 | # - \a freq = frequency 85 | # - \a duty = length of duty cycle (1 full, 0 none) 86 | # - \a offset = offset value 87 | # 88 | # \b Output \b channels: 89 | # - \a out = square wave 90 | # 91 | # 92 | # \b Example: 93 | # \code{.py} 94 | # machine.AddCircuit(type='square', name='sqw') 95 | # machine.AddCircuit(type='square', name='sqw', amp=1, freq=10) 96 | # \endcode 97 | # 98 | class square(Circuit): 99 | 100 | 101 | def __init__(self, machine, name, **keys): 102 | 103 | super(self.__class__, self).__init__( machine, name ) 104 | 105 | self.AddInput("freq") 106 | self.AddInput("amp") 107 | self.AddInput("offset") 108 | self.AddInput("duty") 109 | 110 | self.AddOutput("out") 111 | 112 | self.cCoreID = self.machine.cCore.Add_square(self.machine.cCoreID) 113 | 114 | self.SetInputs(**keys) 115 | 116 | self.phase = 0 117 | 118 | def Initialize (self): 119 | 120 | pass 121 | 122 | 123 | 124 | 125 | def Update (self): 126 | pass 127 | 128 | -------------------------------------------------------------------------------- /src/vafmcore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SINGROUP/PyVAFM/ac77316fe07818261e3d5c9405d8ccf9ef7508ff/src/vafmcore.so --------------------------------------------------------------------------------