├── Derivations ├── GeneralizedBogoliubov.lyx ├── GeneralizedBogoliubov.pdf ├── VPQME.lyx ├── VPQME.pdf ├── VPQME_PAPER.lyx └── VPQME_PAPER.pdf ├── FeynDyn.m ├── VPQME ├── VPQME.m └── sampleInput_VPQME.m ├── _config.yml ├── sampleInput.m ├── sampleInput_2x2_Ohmic_Makri_1995_JCP.m ├── sampleInput_2x2_subOhmic_Nalbach_2010_PRB_figure1.m ├── sampleInput_3x3_Ohmic_Sim_2001_JCP.m ├── sampleInput_7x7_FMO_Nalbach_2011_PRE.m └── sampleInput_7x7_FMO_WilkinsDattani_2015_JCTC.m /Derivations/GeneralizedBogoliubov.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HPQC-LABS/FeynDyn/bdc8cc247cadc2e5ba21149bdf4a69c3ecab3789/Derivations/GeneralizedBogoliubov.pdf -------------------------------------------------------------------------------- /Derivations/VPQME.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HPQC-LABS/FeynDyn/bdc8cc247cadc2e5ba21149bdf4a69c3ecab3789/Derivations/VPQME.pdf -------------------------------------------------------------------------------- /Derivations/VPQME_PAPER.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HPQC-LABS/FeynDyn/bdc8cc247cadc2e5ba21149bdf4a69c3ecab3789/Derivations/VPQME_PAPER.pdf -------------------------------------------------------------------------------- /FeynDyn.m: -------------------------------------------------------------------------------- 1 | %% 1) The paper: N. Dattani (2013) Comp. Phys. Comm. Volume 184, Issue 12, Pg. 2828-2833 , AND 2 | %% 2) The code: N. Dattani (2013) FeynDyn. http://dx.doi.org/10.6084/m9.figshare.823549 3 | 4 | %% Bug reports, suggestions, and requests for extensions are more than encouraged: nike@hpqc.org (if it bounces, you can try nik.dattani@gmail.com or ndattani@uwaterloo.ca) 5 | 6 | %% FEYN DYN, VERSION 2013.11.28 7 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 8 | 9 | function [rho,elapsedTime]=FeynDyn(Nbath,finalPoint,deltaKmax,totalT,rho,H,systemCouplingMatrix,w,dw,J,temperature,wholeDensityMatrixOrJustDiagonals,allPointsORjustFinalPoint,cpuORgpu) 10 | 11 | %% 1. Fundamental constansts 12 | kb=1.3806504*10^(-23); % Joules / Kelvin 13 | hbar=1.054571628*10^(-34); % Joules * seconds 14 | beta=1/(kb*temperature); 15 | %% 2. Setup arrays 16 | M=length(H);M2=M^2; 17 | Svector=eig(systemCouplingMatrix).'; 18 | Svectors=diag(ones(Nbath,1)); 19 | diagonals=diag(reshape(1:M2,M,M)); 20 | upperTriangle=find(triu(reshape(1:M2,M,M))); 21 | initialPoint=0; 22 | dt=totalT/finalPoint; 23 | gridOfTimeIndices=initialPoint:1:finalPoint; % to determine how big to make the K array. This is only necessary for time-dependent OQS hamiltonians. 24 | U=expm(-1i*H*dt/hbar); 25 | Uback=U'; 26 | %% 3. Calculation of eta coefficients 27 | 28 | w=[-fliplr(w) w];J=[-fliplr(J) J]; 29 | temp=beta*hbar*w/2; 30 | MakMak=(1/(hbar*pi))*J.*exp(temp)./(sinh(temp).*w.^2); 31 | 32 | for deltaK=1:deltaKmax%-1 % the -1 is because eta1 isn't meant to go up to deltaKmax, that's what eta 5 is for 33 | eta1(deltaK)=sum(2*MakMak.*((sin(w*dt/2)).^2).*exp(-1i*w*dt*deltaK))*dw; 34 | end 35 | eta2=sum(0.5*MakMak.*(1-exp(-1i*w*dt)))*dw; 36 | for N=2:deltaKmax+1 %N=1 is a dummy index for the eta_00 case, which is covered by eta4 and eta2 37 | eta3(N)=sum(2*MakMak.*((sin(w*dt/4)).^2).*exp(-1i*w*((N-1)*dt - dt/2)))*dw; %the N-1 is because, N is actually starting at 2 and going to deltaKmax+1, instead of going from 1 to deltaKmax 38 | end 39 | eta4=sum(0.5*MakMak.*(1-exp(-1i*w*dt/2)))*dw; 40 | for k=2:deltaKmax+1 %k=1 is a dummy index for the eta_00 case, which is covered by eta4 and eta2 41 | eta5(k)=sum(2*MakMak.*sin(w*dt/4).*sin(w*dt/2).*exp(-1i*w*((k-1)*dt-dt/4)))*dw; %the k-1 is because, k is actually starting at 2 and going to deltaKmax+1, instead of going from 1 to deltaKmax 42 | end 43 | for NminusK=1:deltaKmax%-1 %because eta6 isn't meant to go up to deltaKmax, that's what eta 3 is for 44 | eta6(NminusK)=sum(2*MakMak.*sin(w*dt/4).*sin(w*dt/2).*exp(-1i*w*((NminusK)*dt-dt/4)))*dw; 45 | end 46 | etaK=zeros(1,deltaKmax+1);etaK(1)=eta2;etaK(2:deltaKmax+1)=eta1;%etaK(deltaKmax+1)=eta5(deltaKmax); 47 | etaN=zeros(1,deltaKmax+1);etaN(1)=eta4; 48 | etaN(2:deltaKmax+1)=eta6;%etaN(deltaKmax+1)=eta3(deltaKmax); 49 | kernel=etaK;kernelConj=conj(kernel);kernelEnd=etaN;kernelEndConj=conj(kernelEnd);kernelTD=eta5;kernelTDConj=conj(kernelTD);kernelTDend=eta3;kernelTDendConj=conj(kernelTDend); %kernelTemp(1)=eta5_10, (2)=eta5_20, etc.. kernelTempEnd is same but with eta3 50 | kernelTD(1)=eta4;kernelTDend(1)=eta4; 51 | %% 4. Calculation of K tensor and I tensors 52 | 53 | indicesForF=npermutek(1:M,4); %The way that the indices are defined for the influence functional 54 | indicesForK=[indicesForF(:,3) , indicesForF(:,1) , indicesForF(:,2) ,indicesForF(:,4)]; 55 | 56 | K=U(indicesForK(:,1)+M*(indicesForK(:,2)-1)).*Uback(indicesForK(:,3)+M*(indicesForK(:,4)-1)); %row indicesForK(:,1) of U and column indicesForK(:,2) of U .. see page 8 of lab book 57 | K=repmat(K,1,length(gridOfTimeIndices)); % for time dependent OQS hamiltonians 58 | 59 | [ia,ib] = ndgrid(1:M); 60 | 61 | Sdiff=(kron(Svector,ones(1,M))-kron(ones(1,M),Svector))'; % would not need to transpose the things in the next three lines if Mvector was already a column vector (1:M)' 62 | 63 | I_00=expand(exp(-Sdiff.*(kernelEnd(1)*Svector(1,ib)-kernelEndConj(1)*Svector(1,ia)).'),[M2,1]); %eq(14) on pg 4601 of tensor prop. I. repeated values are for n=1, changing values are for n=0 64 | I_mk=zeros(M2^2,deltaKmax+1);I_mkEnd=I_mk;I_mkTD=I_mk;I_mkTDend=I_mk; %I_00 means I0(sk), I_mk means I(sk,s minus k) ? 65 | I_mk(:,1)=kron(ones(M2,1),exp(-Sdiff.*(kernel(1)*Svector(1,ib)-kernelConj(1)*Svector(1,ia)).')); %eq(14) on pg 4601 of tensor prop. I. repeated values are for 0 (or just n-1?), changing values are for n %might be better to rearrange stuff so that you can use kron if repmat is slow in fortran, %is it better computationally to do this in one line or separate calcs ? This is delatK=0, ie, eq 14 on pg 4604 of Tensor Prop. I, the diff btwn this and the line above is that this is for sk>=1 while line above is for sk=0 ? eta+kk ? 66 | I_mkEnd(:,1)=kron(ones(M2,1),exp(-Sdiff.*(kernelEnd(1)*Svector(1,ib)-kernelEndConj(1)*Svector(1,ia)).')); %repeated values are for 0, changing values are for n %might be better to rearrange stuff so that you can use kron if repmat is slow in fortran, %is it better computationally to do this in one line or separate calcs ? This is delatK=0, eta_NN ? 67 | 68 | for deltaK=1:deltaKmax %should go up to deltaKmax-1 and deltaKmax should be treated separately 69 | I_mk(:,1+deltaK)=exp(-kron((kernel(1+deltaK)*Svector(1,ib)-kernelConj(1+deltaK)*Svector(1,ia)).',Sdiff)); %can't we just make kernel a vector and use kernel(deltaK) ? , %saving kernelConj reduces number of times 'conj.m' has to be called, but adds another variable, which is worse ? %is it bad to have such a big argument in kron ? or should i save it and make 2 lines, depending on your units for kernel, you might need to factor the argument by 1/hbar. The reshaping afterwards must be redundant, we must be able to use kron in such a way that the answer ends up in matrix form , 70 | I_mkTD(:,1+deltaK)=exp(-kron((kernelTD(1+deltaK)*Svector(1,ib)-kernelTDConj(1+deltaK)*Svector(1,ia)).',Sdiff)); %can't we just make kernel a vector and use kernel(deltaK) ? , %saving kernelConj reduces number of times 'conj.m' has to be called, but adds another variable, which is worse ? %is it bad to have such a big argument in kron ? or should i save it and make 2 lines, depending on your units for kernel, you might need to factor the argument by 1/hbar. The reshaping afterwards must be redundant, we must be able to use kron in such a way that the answer ends up in matrix form , 71 | I_mkEnd(:,1+deltaK)=exp(-kron((kernelEnd(1+deltaK)*Svector(1,ib)-kernelEndConj(1+deltaK)*Svector(1,ia)).',Sdiff)); %can't we just make kernel a vector and use kernel(deltaK) ? , %saving kernelConj reduces number of times 'conj.m' has to be called, but adds another variable, which is worse ? %is it bad to have such a big argument in kron ? or should i save it and make 2 lines, depending on your units for kernel, you might need to factor the argument by 1/hbar. The reshaping afterwards must be redundant, we must be able to use kron in such a way that the answer ends up in matrix form , 72 | I_mkTDend(:,1+deltaK)=exp(-kron((kernelTDend(1+deltaK)*Svector(1,ib)-kernelTDendConj(1+deltaK)*Svector(1,ia)).',Sdiff)); %can't we just make kernel a vector and use kernel(deltaK) ? , %saving kernelConj reduces number of times 'conj.m' has to be called, but adds another variable, which is worse ? %is it bad to have such a big argument in kron ? or should i save it and make 2 lines, depending on your units for kernel, you might need to factor the argument by 1/hbar. The reshaping afterwards must be redundant, we must be able to use kron in such a way that the answer ends up in matrix form , 73 | end %kernel(1)=eta_kk, kernel(2)=eta_{k+1,k} 74 | 75 | %% 4.1 Calculation of I tensors with N identical baths 76 | for jj=2:Nbath 77 | Svector2=Svectors(Nbath+1-jj,:); %relationship between Svector and Svector2 78 | Sdiff2=(kron(Svector2,ones(1,M))-kron(ones(1,M),Svector2))'; 79 | 80 | Ij_00=expand(exp(-Sdiff2.*(kernelEnd(1)*Svector2(1,ib)-kernelEndConj(1)*Svector2(1,ia)).'),[M2,1]); 81 | Ij_mk=zeros(M2^2,deltaKmax+1);Ij_mkEnd=Ij_mk;Ij_mkTD=Ij_mk;Ij_mkTDend=Ij_mk; 82 | Ij_mk(:,1)=kron(ones(M2,1),exp(-Sdiff2.*(kernel(1)*Svector2(1,ib)-kernelConj(1)*Svector2(1,ia)).')); 83 | Ij_mkEnd(:,1)=kron(ones(M2,1),exp(-Sdiff2.*(kernelEnd(1)*Svector2(1,ib)-kernelEndConj(1)*Svector2(1,ia)).')); 84 | 85 | for deltaK=1:deltaKmax 86 | Ij_mk(:,1+deltaK)=exp(-kron((kernel(1+deltaK)*Svector2(1,ib)-kernelConj(1+deltaK)*Svector2(1,ia)).',Sdiff2)); 87 | Ij_mkTD(:,1+deltaK)=exp(-kron((kernelTD(1+deltaK)*Svector2(1,ib)-kernelTDConj(1+deltaK)*Svector2(1,ia)).',Sdiff2)); 88 | Ij_mkEnd(:,1+deltaK)=exp(-kron((kernelEnd(1+deltaK)*Svector2(1,ib)-kernelEndConj(1+deltaK)*Svector2(1,ia)).',Sdiff2)); 89 | Ij_mkTDend(:,1+deltaK)=exp(-kron((kernelTDend(1+deltaK)*Svector2(1,ib)-kernelTDendConj(1+deltaK)*Svector2(1,ia)).',Sdiff2)); 90 | end %kernel(1)=eta_kk, kernel(2)=eta_{k+1,k} 91 | 92 | I_00=I_00.*Ij_00; 93 | I_mk=I_mk.*Ij_mk; 94 | I_mkTD=I_mkTD.*Ij_mkTD; 95 | I_mkEnd(:,1)=I_mkEnd(:,1).*Ij_mkEnd(:,1); 96 | I_mkTDend=I_mkTDend.*Ij_mkTDend; 97 | end 98 | 99 | %% 5. Propagation of rho for the first deltaKmax timesteps 100 | A=K(:,1).*I_mkTD(:,1+1).*I_mk(:,1).*I_00.*expand(rho(:,1),[M2,1]); %I_mkTD=I_k0,k=1 I_mk=I_kk, k=1 , I_00=I_NN,k=0 101 | Aend=K(:,1).*I_mkTDend(:,1+1).*I_mkEnd(:,1).*I_00.*expand(rho(:,1),[M2,1]); %I_mkTD=I_N0,N=1 I_mkEnd=I_NN, k=1 , I_00=I_NN,N=0 102 | %K(:,1)=[]; % only for time-dependent system Hamiltonians 103 | 104 | rho(:,2)=sum(reshape(Aend,M2,M2).'); Aend=[]; 105 | 106 | indices=uint32(npermutek(cast(1:M2,'single'),1+1)); %makes 1:4 single precision. One can make them int(8) but then you'd have to use Jan simons's thing (or you could use Matt Fig's MEX, since you're storing it anyway) 107 | 108 | for J=2:deltaKmax %could go to deltaKmax-1 and incorporate the deltaKmax case into the next forloop, but the former way uses I_mkTD and the latter does not. 109 | 110 | indices=horzcat(expand(indices,[M2,1]),repmat((1:M2)',size(indices,1),1));% Making 1:M single precision might help 111 | A=(expand(A,[M2,1])); 112 | %A=A.*repmat(K_k,M2^(J-1),1); % or just read indices like in below lines, whatever's faster [this is implemented in line below because it's needed for OFPF] 113 | A=A.*K((indices(:,end-1)-1)*M2+indices(:,end),1); % %Or just make column of K = J, and forget about the deleting of columns. 114 | K(:,1)=[]; 115 | Aend=A; 116 | for k=0:J-1 % this shouldn't be redone each time, since these lines have no dependence on J 117 | A=A.*I_mk((indices(:,end-k)-1)*M2+indices(:,end),k+1); 118 | Aend=Aend.*I_mkEnd((indices(:,end-k)-1)*M2+indices(:,end),k+1); 119 | end 120 | A=A.*I_mkTD((indices(:,end-J)-1)*M2+indices(:,end),J+1); %the k=J case for forloop above. uses eta_k0 121 | Aend=Aend.*I_mkTDend((indices(:,end-J)-1)*M2+indices(:,end),J+1); %the k=J case for forloop above. uses eta_N0 122 | %whos('A','Aend','indices') 123 | 124 | %weakPaths=find(abs(A)deltaKmax 136 | if strcmpi(cpuORgpu,'GPU');gpuIndex=gpuDevice(1);end 137 | KtimesIpermanent=K((indices(:,end-1)-1)*M2+indices(:,end),1); %predefine ? 138 | KtimesIpermanentEnd=KtimesIpermanent; 139 | %whos 140 | for k=0:deltaKmax % it's probably faster if this tensor is just built as A is in the above forloop ... in fact it seems reading indices is slow, so perhaps even the previous iterations should be done like the tensor propagator below: 141 | KtimesIpermanent=KtimesIpermanent.*I_mk((indices(:,end-k)-1)*M2+indices(:,end),k+1); %when k=deltaKmax, we're using I_mk(:,1+deltaKmax) which used kernel(1+deltaK) which uses eta 5 142 | KtimesIpermanentEnd=KtimesIpermanentEnd.*I_mkEnd((indices(:,end-k)-1)*M2+indices(:,end),k+1);%when k=deltaKmax, we're using I_mkEnd(:,1+deltaKmax) which used kernelEnd(1+deltaK) which uses eta 3 143 | end 144 | 145 | indices=[]; %clear('indices') %when not using parfor 146 | 147 | KtimesIpermanent=reshape(KtimesIpermanent,M2,[]); 148 | KtimesIpermanentEnd=reshape(KtimesIpermanentEnd,M2,[]); 149 | 150 | if strcmpi(cpuORgpu,'GPU') 151 | KtimesIpermanent=gpuArray(KtimesIpermanent);KtimesIpermanentEnd=gpuArray(KtimesIpermanentEnd);A=gpuArray(A);rho=gpuArray(rho(1,:)); 152 | end 153 | for J=deltaKmax+1:finalPoint 154 | Aend=reshape(bsxfun(@times,reshape(sum(reshape(A,[],M2),2),1,[]),KtimesIpermanentEnd),[],1); %see profile.txt for discussion about speed 155 | A=reshape(bsxfun(@times,reshape(sum(reshape(A,[],M2),2),1,[]),KtimesIpermanent),[],1); %could be sped up by using some of the calculations in line above 156 | 157 | Aend=reshape(Aend,M2,[]); % for some reason, switching the M2 and [] and removing the ,2 in the line below alters the beginning 158 | if or(strcmpi(allPointsORjustFinalPoint,'allPoints'),and(strcmpi(allPointsORjustFinalPoint,'justFinalPoint'),J==finalPoint)); 159 | switch wholeDensityMatrixOrJustDiagonals 160 | case 'justDiagonals' 161 | rho(diagonals(1:M-1),J+1)=sum(Aend(diagonals(1:M-1),:),2); % all diagonals but the last 162 | rho(diagonals(end),J+1)=1-sum(rho(:,J+1)); % last diagonal obtained by trace(rho)=1 163 | otherwise 164 | rho(upperTriangle(1:end-1),J+1)=sum(Aend(upperTriangle(1:end-1),:),2); % all of the upper-right triangle of the matrix, except for the last diagonal 165 | rho(diagonals(end),J+1)=1-sum(rho(diagonals(1:end-1),J+1)); % last diagonal obtained by trace(rho)=1 166 | end 167 | disp(['Time step ' num2str(J) '/' num2str(finalPoint) ' has completed successfully after ' num2str(round(toc)) ' seconds! L=' num2str(length(find(A)))]); 168 | end 169 | end 170 | end 171 | elapsedTime=toc; 172 | if strcmpi(cpuORgpu,'GPU') 173 | rho=gather(rho);reset(gpuIndex); 174 | end 175 | 176 | %% SUBROUTINE 1: EXAPND.M 177 | function B = expand(A,S) % Compact version of: http://www.mathworks.co.uk/matlabcentral/fileexchange/24536-expand 178 | 179 | SA = size(A); % Get the size (and number of dimensions) of input. 180 | if length(SA)~=length(S);error('Length of size vector must equal ndims(A). See help.') 181 | elseif any(S~=floor(S));error('The size vector must contain integers only. See help.') 182 | end 183 | for ii = length(SA):-1:1 184 | H = zeros(SA(ii)*S(ii),1); % One index vector into A for each dim. 185 | H(1:S(ii):SA(ii)*S(ii)) = 1; % Put ones in correct places. 186 | T{ii} = cumsum(H); % Cumsumming creates the correct order. 187 | end 188 | B = A(T{:}); % Feed the indices into A. 189 | 190 | %% SUBROUTINE 2: NPERMUTEK.M 191 | function [Matrix,Index] = npermutek(N,K) % Compact version of: http://www.mathworks.co.uk/matlabcentral/fileexchange/11462-npermutek 192 | 193 | if isempty(N) || K == 0 194 | Matrix = [];Index = Matrix; return 195 | elseif floor(K) ~= K || K<0 || ~isreal(K) || numel(K)~=1;error('Second argument should be a real positive integer. See help.') 196 | end 197 | LN = numel(N); % Used in calculating the Matrix and Index. 198 | if K==1;Matrix = N(:);Index = (1:LN).'; return 199 | elseif LN==1;Index = ones(K,1);Matrix = N(1,Index); return 200 | end 201 | CLS = class(N); 202 | if ischar(N); CLS = 'double'; 203 | end 204 | L = LN^K; % This is the number of rows the outputs will have. 205 | Matrix = zeros(L,K,CLS); % Preallocation. 206 | D = diff(N(1:LN)); % Use this for cumsumming later. 207 | LD = length(D); % See comment on LN. 208 | VL = [-sum(D) D].'; % These values will be put into Matrix. 209 | TMP = VL(:,ones(L/LN,1,CLS)); % Instead of repmatting. 210 | Matrix(:,K) = TMP(:); % We don't need to do two these in loop. 211 | Matrix(1:LN^(K-1):L,1) = VL; % The first column is the simplest. 212 | if nargout==1 213 | for ii = 2:K-1 214 | ROWS = 1:LN^(ii-1):L; % Indices into the rows for this col. 215 | TMP = VL(:,ones(length(ROWS)/(LD+1),1,CLS)); % Match dimension. 216 | Matrix(ROWS,K-ii+1) = TMP(:); % Build it up, insert values. 217 | end 218 | else 219 | Index = zeros(L,K,CLS); % Preallocation. 220 | VL2 = ones(size(VL),CLS); % Follow the logic in VL above. 221 | VL2(1) = 1-LN; % These are the drops for cumsum. 222 | TMP2 = VL2(:,ones(L/LN,1,CLS)); % Instead of repmatting. 223 | Index(:,K) = TMP2(:); % We don't need to do two these in loop. 224 | Index(1:LN^(K-1):L,1) = 1; 225 | for ii = 2:K-1 226 | ROWS = 1:LN^(ii-1):L; % Indices into the rows for this col. 227 | F = ones(length(ROWS)/(LD+1),1,CLS); % Don't do it twice! 228 | TMP = VL(:,F); % Match dimensions. 229 | TMP2 = VL2(:,F); 230 | Matrix(ROWS,K-ii+1) = TMP(:); % Build them up, insert values. 231 | Index(ROWS,K-ii+1) = TMP2(:); 232 | end 233 | Index(1,:) = 1; % The first row must be 1 for proper cumsumming. 234 | Index = cumsum(Index); % This is the time hog. 235 | end 236 | Matrix(1,:) = N(1);Matrix = cumsum(Matrix); 237 | if ischar(N);Matrix = char(Matrix);end 238 | -------------------------------------------------------------------------------- /VPQME/VPQME.m: -------------------------------------------------------------------------------- 1 | function drho = VPQME(t,rho,Kt,K,Ot,Omega,kb,hbar,Theta,tau,T,wc,alpha) 2 | %% Interpolate functions 3 | 4 | K = interp1(Kt,K,t); % Interpolate the data set (Kt,K) at time t 5 | Omega = interp1(Ot,Omega,t); % Interpolate the data set (Ot,Omega) at time t 6 | 7 | %% Master equation 8 | drho = zeros (4,1); 9 | drho=[0 0 -Omega 0;0 -K 0 0; Omega 0 -K 0; 0 0 0 0]*rho+[0;0;-Omega/2;-rho(1)]; %Systems of differential equations. 10 | end 11 | -------------------------------------------------------------------------------- /VPQME/sampleInput_VPQME.m: -------------------------------------------------------------------------------- 1 | % Preliminary version of VPQME. 2 | 3 | %% 1) Fundamental constants 4 | 5 | kb=1.38064852e-23; %Boltzmann constant K/K 6 | hbar=1.0545718e-34; %Planck constant Js 7 | 8 | %% 2) Paramaters of the system 9 | 10 | Theta=30; 11 | tau=14e-12; %Full width half maximum in s 12 | T=25; %Temperature in K 13 | wc=2.2e12; %1/s 14 | alpha=pi*0.027*1e-24; % prefactor. In s^2 / rad^2 15 | totalT=4/1e11; %Time of evolution in s 16 | 17 | %% 3)Coefficients of the differential equation 18 | 19 | Ot = linspace(0,5/1e11,100); 20 | Omega=(Theta/(2*tau*sqrt(pi)))*exp(-(Ot/(2*tau)).^2); 21 | 22 | Kt = linspace(0,4/1e11,100); 23 | K=3e11+Kt*0; 24 | 25 | %% 4) Initial density matrix 26 | 27 | rho=[0.5 0.5; 0.5 0.5]; %Initial density matrix 28 | 29 | %% 5) ODE configuration 30 | 31 | options=odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-4 1e-4]); 32 | [t,Y]=ode45(@(t,rho) VPQME(t,rho,Kt,K,Ot,Omega,kb,hbar,Theta,tau,T,wc,alpha),[0 totalT],[rho(1,1) real(rho(1,2)) imag(rho(1,2)) rho(2,2)],options); 33 | %[t,Y]=ode113(@VPQME,[0 totalT],[rho(1,1) real(rho(1,2)) imag(rho(1,2))],options); 34 | 35 | %% 6) Plot of the RDM dynamics 36 | 37 | figure(1);hold('on'); 38 | plotHandle(1)=plot(t,Y(:,1),'k','LineWidth',5); 39 | plotHandle(2)=plot(t,Y(:,2),'r','LineWidth',5); 40 | plotHandle(3)=plot(t,Y(:,3),'b','LineWidth',5); 41 | plotHandle(4)=plot(t,Y(:,4),'color',[0.5 0.5 0.5],'LineWidth',5); 42 | 43 | legendHandle=legend(plotHandle,'$\langle1|\rho(t)|1\rangle$','$\Re\langle1|\rho(t)|0\rangle$','$\Im\langle1|\rho(t)|0\rangle$','$\langle0|\rho(t)|0\rangle$'); 44 | set(legendHandle,'Interpreter','latex','FontSize',32,'LineWidth',2); 45 | 46 | axis([0 totalT min(min(Y)) max(max((Y)))]); 47 | box('on');grid('on'); 48 | set(gca,'XMinorTick','on','YMinorTick','on','LineWidth',2,'FontSize',16); 49 | title('Photon Induced Dephasing','interpreter','latex','FontSize',56); 50 | ylabel('Elements of $\rho(t)$','Interpreter','latex','FontSize',40); 51 | xlabel('Time (seconds)','Interpreter','latex','FontSize',40); 52 | yticklabels('auto'); 53 | 54 | set(gcf, 'Color', 'w'); 55 | set(gcf,'renderer','Painters'); 56 | 57 | %% 7) Plot of pxx. 58 | 59 | figure(2);hold('on'); 60 | plotHandle(1)=plot(t,Y(:,1),'k','LineWidth',5); 61 | 62 | legendHandle=legend(plotHandle,'$\langle X|\rho(t)|X \rangle$'); 63 | set(legendHandle,'Interpreter','latex','FontSize',32,'LineWidth',2); 64 | 65 | axis([0 totalT min(min(Y)) max(max(Y))]); 66 | box('on');grid('on'); 67 | set(gca,'XMinorTick','on','YMinorTick','on','LineWidth',2,'FontSize',16); 68 | title('Photon Induced Dephasing at T=25K','interpreter','latex','FontSize',56); 69 | ylabel('Elements of $\rho(t)$','Interpreter','latex','FontSize',40); 70 | xlabel('Time (seconds)','Interpreter','latex','FontSize',40); 71 | yticklabels('auto'); 72 | 73 | set(gcf, 'Color', 'w'); 74 | set(gcf,'renderer','Painters'); 75 | set(gcf, 'Color', 'w'); 76 | set(gcf,'renderer','Painters'); 77 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /sampleInput.m: -------------------------------------------------------------------------------- 1 | %% Press F5. The real and imaginary parts of will be plotted as a function of time 2 | % for the hamiltonian presented in Comp. Phys. Comm. Volume 184, Issue 12, Pg. 2828-2833 3 | 4 | %% 1. fundamental constants 5 | kb=1.3806504*10^(-23); % Joules / Kelvin 6 | hbar=1.054571628*10^(-34); % Joule * seconds 7 | 8 | %% 2. temperature 9 | temperature=25; 10 | beta=1/(kb*temperature); 11 | 12 | %% 3. system hamiltonian 13 | Omega=hbar*1e12*pi/8; % Rabi frequency in Joules 14 | H=[0 Omega/2; Omega/2 0]; % System hamiltonian in Joules 15 | 16 | %% 4. initial denisty matrix 17 | rhoInitial=[0 0; 0 1]; 18 | 19 | %% 5. system coupling matrix 20 | Nbaths=1; % Number of baths 21 | systemCouplingMatrix=[0 0;0 1]; % The system is coupled to the bath via |1X1| 22 | %systemCouplingMatrix=[1 0;0 -1]; % The system is coupled to the bath via sigma_z 23 | 24 | %% 6. spectral distribution function 25 | alpha=0.027*pi; % prefactor. In ps^2 / rad^2 26 | wc=2.2; % cutoff frequency. In rad/ps 27 | dw=0.01; % stepsize for w in J(w). In rad/ps 28 | w=dw:dw:14; % must start with dw because coth(0)=infinity. In rad/ps 29 | J=alpha*exp(-(w/wc).^2).*w.^3;% spectral density. In rad/ps 30 | 31 | J=J*1e12*hbar; % spectral distribution function. In Joules 32 | 33 | w=w*1e12; % w in s-1 34 | dw=dw*1e12; % dw in s-1 35 | 36 | %% 7. numerical parameters for Feynman integral 37 | deltaKmax=9; % number of time steps before memory kernel dies 38 | totalT=10/1e12; % total time for the simulation, in seconds 39 | dt=33/totalT; % size of time step (delta t) 40 | finalPoint=round(dt*totalT); % number of timesteps in total 41 | allPointsORjustFinalPoint='allPoints'; % do you just want the density matrix at time=totalT ? or do you want it at every point until then 42 | cpuORgpu='cpu'; 43 | 44 | %% 8. build input array that represents the densitry matrix (flattened to a column vector) as a function of time (where the columns represent the time steps) 45 | rho=zeros(numel(H),finalPoint+1); 46 | rho(:,1)=reshape(rhoInitial.',[],1); % I'm not sure about the transpose, since I'm not sure about labeling of the states in the column vector for the purposes of the final sum function. 47 | 48 | %% 9. run the program and plot only <0|rho|0> and <1|rho|1> as a function of time 49 | wholeDensityMatrixOrJustDiagonals='justDiagonals'; 50 | 51 | [rho_onlyDiagonals,elapsedTime_onlyDiagonals]=FeynDyn(Nbaths,finalPoint,deltaKmax,totalT,rho,H,systemCouplingMatrix,w,dw,J,temperature,wholeDensityMatrixOrJustDiagonals,allPointsORjustFinalPoint,cpuORgpu); 52 | 53 | figure(1);hold('on') 54 | plot(0:totalT/finalPoint:totalT,real(rho_onlyDiagonals(1,:))); 55 | plot(0:totalT/finalPoint:totalT,real(rho_onlyDiagonals(4,:))); 56 | xlabel('time (seconds)'); 57 | 58 | %% 10. run the program and plot all elements of the density matrix as a function of time 59 | wholeDensityMatrixOrJustDiagonals='wholeDensityMatrix'; 60 | 61 | [rho_allElements,elapsedTime_allElements]=FeynDyn(Nbaths,finalPoint,deltaKmax,totalT,rho,H,systemCouplingMatrix,w,dw,J,temperature,wholeDensityMatrixOrJustDiagonals,allPointsORjustFinalPoint,cpuORgpu); 62 | 63 | figure(2);hold('on') 64 | plot(0:totalT/finalPoint:totalT,real(rho_allElements(1,:))); 65 | plot(0:totalT/finalPoint:totalT,real(rho_allElements(3,:)),'r');plot(0:totalT/finalPoint:totalT,imag(rho_allElements(3,:)),'--r'); 66 | plot(0:totalT/finalPoint:totalT,real(rho_allElements(3,:)),'r');plot(0:totalT/finalPoint:totalT,-imag(rho_allElements(3,:)),'--r'); 67 | plot(0:totalT/finalPoint:totalT,real(rho_allElements(4,:))); 68 | xlabel('time (seconds)'); -------------------------------------------------------------------------------- /sampleInput_2x2_Ohmic_Makri_1995_JCP.m: -------------------------------------------------------------------------------- 1 | %% Press F5. A figure from Nancy Makri's 1995 JCP paper will be plotted. 2 | 3 | %% 1. fundamental constants 4 | kb=1.3806504*10^(-23); % Joules / Kelvin 5 | hbar=1.054571628*10^(-34); % Joule * seconds 6 | 7 | %% 2. temperature 8 | temperature=1/5/kb; 9 | beta=1/(kb*temperature); 10 | 11 | %% 3. system hamiltonian 12 | Omega=1/hbar;%hbar*1e12*pi/8; % Rabi frequency in Joules %bho 13 | H=hbar*[0 Omega; Omega 0]; % System hamiltonian in Joules 14 | %H=hbar*[Omega Omega; Omega -Omega]; 15 | 16 | %% 4. initial denisty matrix 17 | rhoInitial=[1 0; 0 0]; 18 | 19 | %% 5. system coupling matrix 20 | Nbaths=1; 21 | %systemCouplingMatrix=[0 0;0 1]; % The system is coupled to the bath via |1X1| 22 | systemCouplingMatrix=[1 0;0 -1]; % The system is coupled to the bath via sigma_z 23 | 24 | %% 6. spectral distribution function 25 | alpha=0.05*pi*hbar; % prefactor. In ps^2 / rad^2 26 | wc=7.5*Omega; % cutoff frequency. In rad/ps 27 | dw=0.01*Omega; % stepsize for w in J(w). In rad/ps 28 | w=dw:dw:10*wc; % must start with dw because coth(0)=infinity. In rad/ps 29 | J=alpha*exp(-(w/wc)).*w;% spectral density. In rad/ps 30 | 31 | %J=J*1e12*hbar; % spectral distribution function. In Joules 32 | 33 | %w=w*1e12; % w in s-1 34 | %dw=dw*1e12; % dw in s-1 35 | 36 | %% 7. numerical parameters for Feynman integral 37 | deltaKmax=1; % number of time steps before memory kernel dies 38 | totalT=25/Omega;%10/1e12; % total time for the simulation, in seconds 39 | %totalT=15/Omega; 40 | dt=totalT/100; % size of time step (delta t) 41 | finalPoint=round(totalT/dt); % number of timesteps in total 42 | allPointsORjustFinalPoint='allPoints'; % do you just want the density matrix at time=totalT ? or do you want it at every point until then 43 | cpuORgpu='cpu'; 44 | 45 | %% 8. build input array that represents the densitry matrix (flattened to a column vector) as a function of time (where the columns represent the time steps) 46 | rho=zeros(numel(H),finalPoint+1); 47 | rho(:,1)=reshape(rhoInitial.',[],1); % I'm not sure about the transpose, since I'm not sure about labeling of the states in the column vector for the purposes of the final sum function. 48 | 49 | %% 9. run the program and plot only <0|rho|0> and <1|rho|1> as a function of time 50 | % wholeDensityMatrixOrJustDiagonals='JustDiagonals'; 51 | % 52 | % [rho_onlyDiagonals,elapsedTime_onlyDiagonals]=FeynDyn(Nbaths,finalPoint,deltaKmax,totalT,rho,H,systemCouplingMatrix,w,dw,J,temperature,wholeDensityMatrixOrJustDiagonals,allPointsORjustFinalPoint,cpuORgpu); 53 | % 54 | % figure(1);hold('on') 55 | % plot(0:totalT/finalPoint:totalT,real(rho_onlyDiagonals(1,:))); 56 | % plot(0:totalT/finalPoint:totalT,real(rho_onlyDiagonals(4,:))); 57 | % xlabel('time (seconds)'); 58 | %% 10. run the program and plot all elements of the density matrix as a function of time 59 | wholeDensityMatrixOrJustDiagonals='wholeDensityMatrix'; 60 | 61 | [rho_allElements,elapsedTime_allElements]=FeynDyn(Nbaths,finalPoint,deltaKmax,totalT,rho,H,systemCouplingMatrix,w,dw,J,temperature,wholeDensityMatrixOrJustDiagonals,allPointsORjustFinalPoint,cpuORgpu); 62 | totalT=totalT*Omega; 63 | figure(2);hold('on') 64 | plot(0:totalT/finalPoint:totalT,(real(rho_allElements(1,:))-real(rho_allElements(4,:))),'k'); 65 | % plot(0:totalT/finalPoint:totalT,real(rho_allElements(1,:))); 66 | % plot(0:totalT/finalPoint:totalT,real(rho_allElements(3,:)),'r');plot(0:totalT/finalPoint:totalT,imag(rho_allElements(3,:)),'--r'); 67 | % plot(0:totalT/finalPoint:totalT,real(rho_allElements(3,:)),'r');plot(0:totalT/finalPoint:totalT,-imag(rho_allElements(3,:)),'--r'); 68 | % plot(0:totalT/finalPoint:totalT,real(rho_allElements(4,:))); 69 | xlabel('time (seconds)'); 70 | 71 | -------------------------------------------------------------------------------- /sampleInput_2x2_subOhmic_Nalbach_2010_PRB_figure1.m: -------------------------------------------------------------------------------- 1 | %% Bearing in mind the effort that went into the development of FeynDyn, 2 | %% the author would indeed appreciate if users can please cite: 3 | %% 1) The paper: N. Dattani (2013) Comp. Phys. Comm. Volume 184, Issue 12, Pg. 2828-2833 , and 4 | %% 2) The code: N. Dattani (2013) FeynDyn. http://dx.doi.org/10.6084/m9.figshare.823549 5 | 6 | %% To make sure your code is the most updated version, please e-mail dattani.nike@gmail.com 7 | %% Bug reports, suggestions, and requests for extensions are more than encouraged: dattani.nike@gmail.com 8 | 9 | %% This program is protected by copyright law. Nike S. Dattani , 13/8/12 10 | 11 | %% This sample input file, upon pressing F5, plots the real and imaginary parts of as a function 12 | % of time for the hamiltonian presented in Comp. Phys. Comm. Volume 184, Issue 12, Pg. 2828-2833 13 | 14 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 15 | 16 | %% 1. fundamental constants 17 | kb=1.3806504*10^(-23); % Joules / Kelvin 18 | hbar=1.054571628*10^(-34); % Joule * seconds 19 | 20 | %% 2. temperature 21 | temperature=1/100/kb; 22 | beta=1/(kb*temperature); 23 | 24 | %% 3. system hamiltonian 25 | wc=1/hbar; 26 | Omega=0.1*wc;%hbar*1e12*pi/8; % Rabi frequency in Joules %bho 27 | H=0.5*hbar*[0 Omega; Omega 0]; % System hamiltonian in Joules 28 | %H=hbar*[Omega Omega; Omega -Omega]; 29 | 30 | %% 4. initial denisty matrix 31 | rhoInitial=[1 0; 0 0]; 32 | 33 | %% 5. system coupling matrix\ 34 | %systemCouplingMatrix=[0 0;0 1]; % The system is coupled to the bath via |1X1| 35 | systemCouplingMatrix=[1 0;0 -1]; % The system is coupled to the bath via sigma_z 36 | 37 | %% 6. spectral distribution function 38 | Nbaths=1; % Number of baths 39 | alpha=0.9*0.022*pi*hbar/2; % prefactor. In ps^2 / rad^2 40 | %wc=10*Omega; % cutoff frequency. In rad/ps 41 | dw=0.01*wc; % stepsize for w in J(w). In rad/ps 42 | w=dw:dw:10*wc; % must start with dw because coth(0)=infinity. In rad/ps 43 | %J=alpha*exp(-(w/wc)).*w; % spectral density. In rad/psJ 44 | J=alpha*wc^0.75.*w.^0.25; 45 | 46 | %J=J*1e12*hbar; % spectral distribution function. In Joules 47 | 48 | %w=w*1e12; % w in s-1 49 | %dw=dw*1e12; % dw in s-1 50 | 51 | %% 7. numerical parameters for Feynman integral 52 | deltaKmax=12; % number of time steps before memory kernel dies 53 | totalT=200/wc;%10/1e12; % total time for the simulation, in seconds 54 | %totalT=15/Omega; 55 | dt=totalT/60; % size of time step (delta t) 56 | finalPoint=round(totalT/dt); % number of timesteps in total 57 | allPointsORjustFinalPoint='allPoints'; % do you just want the density matrix at time=totalT ? or do you want it at every point until then 58 | cpuORgpu='cpu'; 59 | 60 | %% 8. build input array that represents the densitry matrix (flattened to a column vector) as a function of time (where the columns represent the time steps) 61 | rho=zeros(numel(H),finalPoint+1); 62 | rho(:,1)=reshape(rhoInitial.',[],1); % I'm not sure about the transpose, since I'm not sure about labeling of the states in the column vector for the purposes of the final sum function. 63 | 64 | %% 9. run the program and plot only <0|rho|0> and <1|rho|1> as a function of time 65 | % wholeDensityMatrixOrJustDiagonals='JustDiagonals'; 66 | % 67 | % [rho_onlyDiagonals,elapsedTime_onlyDiagonals]=FeynDynCode(finalPoint,deltaKmax,totalT,rho,H,systemCouplingMatrix,w,dw,J,temperature,wholeDensityMatrixOrJustDiagonals,allPointsORjustFinalPoint,cpuORgpu); 68 | % 69 | % figure(1);hold('on') 70 | % plot(0:totalT/finalPoint:totalT,real(rho_onlyDiagonals(1,:))); 71 | % plot(0:totalT/finalPoint:totalT,real(rho_onlyDiagonals(4,:))); 72 | % xlabel('time (seconds)'); 73 | %% 10. run the program and plot all elements of the density matrix as a function of time 74 | wholeDensityMatrixOrJustDiagonals='wholeDensityMatrix'; 75 | 76 | [rho_allElements,elapsedTime_allElements]=FeynDynCode(Nbaths,finalPoint,deltaKmax,totalT,rho,H,systemCouplingMatrix,w,dw,J,temperature,wholeDensityMatrixOrJustDiagonals,allPointsORjustFinalPoint,cpuORgpu); 77 | 78 | figure(3);hold('on') 79 | totalT=totalT*wc; 80 | plot(0:totalT/finalPoint*Omega:totalT*Omega,(real(rho_allElements(1,:))-real(rho_allElements(4,:))),'k'); 81 | % plot(0:totalT/finalPoint:totalT,real(rho_allElements(1,:))); 82 | % plot(0:totalT/finalPoint:totalT,real(rho_allElements(3,:)),'r');plot(0:totalT/finalPoint:totalT,imag(rho_allElements(3,:)),'--r'); 83 | % plot(0:totalT/finalPoint:totalT,real(rho_allElements(3,:)),'r');plot(0:totalT/finalPoint:totalT,-imag(rho_allElements(3,:)),'--r'); 84 | %plot(0:totalT/finalPoint:totalT,real(rho_allElements(4,:))); 85 | xlabel('time (\omega_c^-^1)'); 86 | 87 | -------------------------------------------------------------------------------- /sampleInput_3x3_Ohmic_Sim_2001_JCP.m: -------------------------------------------------------------------------------- 1 | %% Press F5. Figures 5 and 6 will be plotted from Eunji Sim (2001) "Quantum dynamics for a system coupled to slow baths: 2 | % On-the-fly filtered propagator method", J. Chem. Phys. 115, 10, pg. 4450 3 | 4 | %% fundamental constants 5 | kb=1.3806504*10^(-23); % Joules / Kelvin 6 | hbar=1.054571628*10^(-34); % Joule * seconds 7 | 8 | %% temperature 9 | beta=0.72/hbar; 10 | temperature=1/(kb*beta); 11 | 12 | %% system hamiltonian 13 | V12=0.066667;V23=V12; 14 | E2=-1.3333333;E3=2*E2; 15 | 16 | H=[0 V12 0; 17 | V12 E2 V23; 18 | 0 V23 E3]*hbar; 19 | 20 | %% initial denisty matrix 21 | rhoInitial=[1 0 0; 22 | 0 0 0; 23 | 0 0 0]; 24 | 25 | %% system coupling matrix 26 | Nbaths=1; % Number of baths. 27 | systemCouplingMatrix=diag([-1 0 1]); 28 | 29 | %% spectral distribution function 30 | alpha=2.094*hbar; % multiplied by hbar because FeynDyn has an erroneous hbar in MakMak 31 | wc=1.0; % cutoff frequency 32 | dw=0.0001; 33 | w=dw:dw:14; % must start with dw because coth(0)=infinity 34 | J=alpha*exp(-(w/wc).^1).*w.^1; % spectral density in ps-1 35 | 36 | %% numerical parameters for Feynman integral 37 | finalPoint=3000; % number of timesteps in total 38 | deltaKmax=6; % number of time steps before memory kernel dies 39 | totalT=1000; % total time for the simulation, in seconds 40 | allPointsORjustFinalPoint='allPoints'; % do you just want the density matrix at time=totalT ? or do you want it at every point until then 41 | cpuORgpu='cpu'; 42 | 43 | %% build input array that represents the densitry matrix (flattened to a column vector) as a function of time (where the columns represent the time steps) 44 | rho=zeros(numel(H),finalPoint+1); 45 | rho(:,1)=reshape(rhoInitial.',[],1); 46 | 47 | %% run the program to calculate all density matrix elements 48 | wholeDensityMatrixOrJustDiagonals='wholeMatrix'; 49 | 50 | [rho,elapsedTime]=FeynDyn(Nbaths,finalPoint,deltaKmax,totalT,rho,H,systemCouplingMatrix,w,dw,J,temperature,wholeDensityMatrixOrJustDiagonals,allPointsORjustFinalPoint,cpuORgpu); 51 | 52 | %% Plot figure 5 of Eunji Sim's paper: just diagonals 53 | figure(5);hold('on') 54 | plot(0:totalT/finalPoint:totalT,real(rho(1,:))); 55 | plot(0:totalT/finalPoint:totalT,real(rho(5,:))); 56 | plot(0:totalT/finalPoint:totalT,real(rho(9,:))); 57 | xlabel('time'); 58 | 59 | %% Plot figure 6 of Eunji Sim's paper: just rho(2,3) 60 | figure(6);hold('on') 61 | plot(0:totalT/finalPoint:totalT,real(rho(8,:))); 62 | xlabel('time'); 63 | -------------------------------------------------------------------------------- /sampleInput_7x7_FMO_Nalbach_2011_PRE.m: -------------------------------------------------------------------------------- 1 | %% Bearing in mind the effort that went into the development of FeynDyn, 2 | %% the author would indeed appreciate if users can please cite: 3 | %% 1) The paper: N. Dattani (2013) Comp. Phys. Comm. Volume 184, Issue 12, Pg. 2828-2833 , and 4 | %% 2) The code: N. Dattani (2013) FeynDyn. http://dx.doi.org/10.6084/m9.figshare.823549 5 | 6 | %% To make sure your code is the most updated version, please e-mail dattani.nike@gmail.com 7 | %% Bug reports, suggestions, and requests for extensions are more than encouraged: dattani.nike@gmail.com 8 | 9 | %% This program is protected by copyright law. Nike S. Dattani , 13/8/12 10 | 11 | %% This sample input file, upon pressing F5, plots the real and imaginary parts of as a function 12 | % of time for the hamiltonian presented in Comp. Phys. Comm. Volume 184, Issue 12, Pg. 2828-2833 13 | 14 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 15 | 16 | %% 1. fundamental constants 17 | kb=1.3806504*10^(-23); % Joules / Kelvin 18 | hbar=1.054571628*10^(-34); % Joule * seconds 19 | 20 | %% 2. temperature 21 | temperature=77; 22 | beta=1/(kb*temperature); 23 | 24 | %% 3. system hamiltonian 25 | %Omega=hbar*1e12*pi/8; % Rabi frequency in Joules 26 | wavenumbers2joules=1.9864475e-23; 27 | Jda=100/5.034e22; 28 | epsilon_d=200/5.034e22; 29 | epsilon_a=300/5.034e22; 30 | %H=[0 Omega/2; Omega/2 0]; % System hamiltonian in Joules 31 | %H=Jda*[0 1;1 0]+[epsilon_d 0;0 epsilon_a]; 32 | H=wavenumbers2joules*[240 -87.7 5.5 -5.9 6.7 -13.7 -9.9 33 | -87.7 315 30.8 8.2 0.7 11.8 4.3 34 | 5.5 30.8 0 -53.5 -2.2 -9.6 6.0 35 | -5.9 8.2 -53.5 130 -70.7 -17.0 -63.3 36 | 6.7 0.7 -2.2 -70.7 285 81.1 -1.3 37 | -13.7 11.8 -9.6 -17.0 81.1 435 39.7 38 | -9.9 4.3 6.0 -63.3 -1.3 39.7 245]; 39 | 40 | %% 4. initial denisty matrix 41 | Nbaths=7; 42 | rhoInitial=zeros(Nbath); 43 | rhoInitial(1)=1; 44 | 45 | %% 5. system coupling matrix 46 | systemCouplingMatrix=diag(ones(7,1)); 47 | %systemCouplingMatrix=[0 0;0 1]; % The system is coupled to the bath via |1X1| 48 | %systemCouplingMatrix=[1 0;0 -1]; % The system is coupled to the bath via sigma_z 49 | 50 | %% 6. spectral distribution function 51 | 52 | wc=1/(50e-15);%53/5.034e22; % cutoff frequency. In rad/ps 53 | dw=0.00001*wc; % stepsize for w in J(w). In rad/ps 54 | w=dw:dw:50*wc; % must start with dw because coth(0)=infinity. In rad/ps 55 | lamda=35*wavenumbers2joules;%2/pi*Jda/5; 56 | %J=pi*lamda/wc*exp(-(w/wc)).*w;% spectral density. In rad/ps 57 | 58 | %J=J*1e12*hbar; % spectral distribution function. In Joules 59 | J=pi*lamda*(w*wc)./((wc^2+w.^2)); 60 | 61 | %w=w*1e12; % w in s-1 62 | %dw=dw*1e12; % dw in s-1 63 | 64 | %% 7. numerical parameters for Feynman integral 65 | deltaKmax=3; % number of time steps before memory kernel dies 66 | %totalT=10/1e12; % total time for the simulation, in seconds 67 | totalT=900/1e15; 68 | %dt=totalT/200; % size of time step (delta t) 69 | finalPoint=84; % number of timesteps in total 70 | allPointsORjustFinalPoint='allPoints'; % do you just want the density matrix at time=totalT ? or do you want it at every point until then 71 | cpuORgpu='cpu'; 72 | 73 | %% 8. build input array that represents the densitry matrix (flattened to a column vector) as a function of time (where the columns represent the time steps) 74 | rho=zeros(numel(H),finalPoint+1); 75 | rho(:,1)=reshape(rhoInitial.',[],1); % I'm not sure about the transpose, since I'm not sure about labeling of the states in the column vector for the purposes of the final sum function. 76 | 77 | %% 9. run the program and plot only <0|rho|0> and <1|rho|1> as a function of time 78 | % wholeDensityMatrixOrJustDiagonals='justDiagonals'; 79 | % 80 | % [rho_onlyDiagonals,elapsedTime_onlyDiagonals]=FeynDynCode(finalPoint,deltaKmax,totalT,rho,H,systemCouplingMatrix,w,dw,J,temperature,wholeDensityMatrixOrJustDiagonals,allPointsORjustFinalPoint,cpuORgpu); 81 | % 82 | % figure(1);hold('on') 83 | % plot(0:totalT/finalPoint:totalT,real(rho_onlyDiagonals(1,:))); 84 | % plot(0:totalT/finalPoint:totalT,real(rho_onlyDiagonals(4,:))); 85 | % xlabel('time (seconds)'); 86 | 87 | %% 10. run the program and plot all elements of the density matrix as a function of time 88 | wholeDensityMatrixOrJustDiagonals='wholeDensityMatrix'; 89 | 90 | [rho_allElements,elapsedTime_allElements]=FeynDynCode(Nbaths,finalPoint,deltaKmax,totalT,rho,H,systemCouplingMatrix,w,dw,J,temperature,wholeDensityMatrixOrJustDiagonals,allPointsORjustFinalPoint,cpuORgpu); 91 | figure(2);hold('on') 92 | plot(0:totalT/finalPoint:totalT,real(rho_allElements(1,:)),'r','LineWidth',5); 93 | plot(0:totalT/finalPoint:totalT,real(rho_allElements(9,:)),'g','LineWidth',5); 94 | plot(0:totalT/finalPoint:totalT,real(rho_allElements(17,:)),'b','LineWidth',5); 95 | plot(0:totalT/finalPoint:totalT,real(rho_allElements(25,:)),'m','LineWidth',5); 96 | plot(0:totalT/finalPoint:totalT,real(rho_allElements(33,:)),'c','LineWidth',5); 97 | plot(0:totalT/finalPoint:totalT,real(rho_allElements(41,:)),'y','LineWidth',5); 98 | plot(0:totalT/finalPoint:totalT,real(rho_allElements(49,:)),'Color',[0.5 0.5 0.5],'LineWidth',5); 99 | %plot(0:totalT/finalPoint:totalT,real(rho_allElements(3,:)),'r');plot(0:totalT/finalPoint:totalT,imag(rho_allElements(3,:)),'--r'); 100 | %plot(0:totalT/finalPoint:totalT,-real(rho_allElements(3,:)),'r');plot(0:totalT/finalPoint:totalT,imag(rho_allElements(3,:)),'--r'); 101 | %plot(0:totalT/finalPoint:totalT,real(rho_allElements(4,:))); 102 | xlabel('time (seconds)'); 103 | %save('rho.dat','rho_allElements','-ascii','-double'); -------------------------------------------------------------------------------- /sampleInput_7x7_FMO_WilkinsDattani_2015_JCTC.m: -------------------------------------------------------------------------------- 1 | %% Bearing in mind the effort that went into the development of FeynDyn, 2 | %% the author would indeed appreciate if users can please cite: 3 | %% 1) The paper: N. Dattani (2013) Comp. Phys. Comm. Volume 184, Issue 12, Pg. 2828-2833 , and 4 | %% 2) The code: N. Dattani (2013) FeynDyn. http://dx.doi.org/10.6084/m9.figshare.823549 5 | 6 | %% To make sure your code is the most updated version, please e-mail dattani.nike@gmail.com 7 | %% Bug reports, suggestions, and requests for extensions are more than encouraged: dattani.nike@gmail.com 8 | 9 | %% This program is protected by copyright law. Nike S. Dattani , 13/8/12 10 | 11 | %% This sample input file, upon pressing F5, plots the 7 diagonals as in Fig. 1 of 12 | % 2015 Wilkins & Dattani, J. Chem. Thy. Comp. 13 | 14 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 15 | 16 | %% 1. fundamental constants 17 | kb=1.3806504*10^(-23); % Joules / Kelvin 18 | hbar=1.054571628*10^(-34); % Joule * seconds 19 | 20 | %% 2. temperature 21 | temperature=77; % Kelvin 22 | beta=1/(kb*temperature); 23 | 24 | %% 3. system hamiltonian 25 | wavenumbers2joules=1.9864475e-23; 26 | 27 | H=[410.0 -87.7 5.5 -5.9 6.7 -13.7 -9.9 % H in wavenumbers (cm-1) 28 | 0.0 530.0 30.8 8.2 0.7 11.8 4.3 29 | 0.0 0.0 210.0 -53.5 -2.2 -9.6 6.0 30 | 0.0 0.0 0.0 320.0 -70.7 -17.0 -63.3 31 | 0.0 0.0 0.0 0.0 480.0 81.1 -1.3 32 | 0.0 0.0 0.0 0.0 0.0 630.0 39.7 33 | 0.0 0.0 0.0 0.0 0.0 0.0 440.0]; 34 | 35 | H=H+H'-diag(diag(H)); % Fill lower triangle, subtract diagonals to avoid doubling 36 | H=wavenumbers2joules*H; % H in Joules 37 | 38 | %% 4. initial denisty matrix 39 | rhoInitial=zeros(size(H)); 40 | rhoInitial(1)=1; % Excitation starts localized at site 1 41 | 42 | %% 5. system coupling matrix 43 | Nbaths=7; % Number of baths 44 | systemCouplingMatrix=diag(ones(Nbaths,1)); % Each site i couples to its bath via |iXi| coupling 45 | 46 | %% 6. spectral distribution function 47 | wc=1/(50e-15); % cutoff frequency. In rad/ps 48 | dw=0.00001*wc; % stepsize for w in J(w). In rad/ps 49 | w=dw:dw:50*wc; % must start with dw because coth(0)=infinity. In rad/ps 50 | lamda=35*wavenumbers2joules; % reorganization energy in Joules 51 | J=2*lamda*(w*wc)./((wc^2+w.^2)); % spectral density in Joules 52 | 53 | %% 7. numerical parameters for Feynman integral 54 | deltaKmax=3; % number of time steps before memory kernel dies 55 | totalT=1000/1e15; % total time for the simulation, in seconds 56 | finalPoint=50; % number of timesteps in total 57 | allPointsORjustFinalPoint='allPoints'; % do you just want the density matrix at time=totalT ? or do you want it at every point until then 58 | cpuORgpu='cpu'; 59 | 60 | %% 8. build input array that represents the densitry matrix (flattened to a column vector) as a function of time (where the columns represent the time steps) 61 | rho=zeros(numel(H),finalPoint+1); 62 | rho(:,1)=reshape(rhoInitial.',[],1); % I'm not sure about the transpose, since I'm not sure about labeling of the states in the column vector for the purposes of the final sum function. 63 | 64 | %% 9. run the program and plot all diagoal elements of the density matrix as a function of time 65 | wholeDensityMatrixOrJustDiagonals='justDiagonals'; 66 | [rho,elapsedTime]=FeynDyn(Nbaths,finalPoint,deltaKmax,totalT,rho,H,systemCouplingMatrix,w,dw,J,temperature,wholeDensityMatrixOrJustDiagonals,allPointsORjustFinalPoint,cpuORgpu); 67 | 68 | %% 69 | figure(1);hold('on');box('on') 70 | axis([0 totalT 0 1]) 71 | mesh=0:totalT/finalPoint:totalT; 72 | splineMesh=0:totalT/finalPoint/100:totalT; 73 | plot(splineMesh,spline(mesh,real(rho(1,:)),splineMesh),'r','LineWidth',5); 74 | plot(splineMesh,spline(mesh,real(rho(9,:)),splineMesh),'g','LineWidth',5); 75 | plot(splineMesh,spline(mesh,real(rho(17,:)),splineMesh),'b','LineWidth',5); 76 | plot(splineMesh,spline(mesh,real(rho(25,:)),splineMesh),'m','LineWidth',5); 77 | plot(splineMesh,spline(mesh,real(rho(33,:)),splineMesh),'c','LineWidth',5); 78 | plot(splineMesh,spline(mesh,real(rho(41,:)),splineMesh),'y','LineWidth',5); 79 | plot(splineMesh,spline(mesh,real(rho(49,:)),splineMesh),'Color',[0.5 0.5 0.5],'LineWidth',5); 80 | %plot(0:totalT/finalPoint:totalT,real(rho(3,:)),'r');plot(0:totalT/finalPoint:totalT,imag(rho(3,:)),'--r'); 81 | xlabel('time (seconds)'); 82 | --------------------------------------------------------------------------------