Skip to content

Commit

Permalink
Start fixing Indo to work like the others
Browse files Browse the repository at this point in the history
  • Loading branch information
crcollins committed Jul 31, 2013
1 parent 5ef703d commit 6d43aba
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 147 deletions.
104 changes: 41 additions & 63 deletions @Indo/Indo.m
Original file line number Diff line number Diff line change
@@ -1,90 +1,68 @@
classdef Indo < handle
properties (SetAccess = private)
% Input parameters
config % see defaultConfig() for contents
dataPath % directory for the data (do not end with \)
jobName % will read structure from ampac out file jobname.out
parameterFile
% and store indo results in jobname.ido
% Atomic basis set:
norb % number of atomic basis functions, and hf orbitals
aorbAtom % (1,i) atom on which the ith atomic orbital resides
aorbType % (1,i) type of ith atomic orbital
classdef Indo < Base
properties
config

norb % number of atomic basis functions, and hf orbitals
aorbAtom % (1,i) atom on which the ith atomic orbital resides
aorbType % (1,i) type of ith atomic orbital
% {s1=0,s2=1,p2x=2,p2y=3,p2z=4,s3=5,p3x=6,p3y=7,p3z=8}
% Hartree Fock Results:
nfilled % number of filled molecular orbitals
hfE % HF ground state energy
orbE % (1,i) energy of ith orbital
orb % (i,j) ith component of jth orbital
indoOutput % output from indo
% SCI results
nfilled % number of filled molecular orbitals
hfE % HF ground state energy
orbE % (1,i) energy of ith orbital
orb % (i,j) ith component of jth orbital
nsci % number of sci states, with first being ground state
nscibasis % number of basis functions (first being ground state)
esci % (1,i) energies of ith sci state
r %( i,j, icomp) transition (position) operator icomp = x,y,z
wfsci % (i,j) ith component of jth state
ehsci % (i,1) hole of the ith SCI basis function (0 if GS)
% (i,2) = elec of the ith SCI basis function (0 if GS)

indoExe = '"c:\mscpp\demo-dci\Release\demo-dci.exe"';
end % properties
end
properties (Transient)
osc % (1,i) oscillator strength from gs to state i
rx % r(:,:,1) for backwards compatibility, don't use now
ry % r(:,:,2)
rz % r(:,:,3)
end
methods (Access = private)
readIndo(obj);
end
methods (Static)
function res = defaultConfig()
res.charge = 1;
res.norbs = 100;
res.nstates = 25;
res.field = [0,0,0];
res.potfile = '';
end
end
methods
function res = Indo(ConfigIn, dataPathIn, jobNameIn, parameterFileIn)
if (nargin < 1)
res.config = Indo.defaultConfig();
else
res.config = ConfigIn;
end
if (nargin < 2)
res.dataPath = 'data';
else
res.dataPath = dataPathIn;
end
function obj = Indo(dataPath, template, params, paramfile)
obj = obj@Base(dataPath, template, struct);

if (nargin < 3)
res.jobName = 'jobname';
res.config = Indo.defaultConfig();
else
res.jobName = jobNameIn;
res.config = params;
end
if (nargin < 4)
res.parameterFile = 'parafile';
res.parameterFile = 'parafile';
else
res.parameterFile = parameterFileIn;
res.parameterFile = paramfile;
end
fileprefix= [res.dataPath,res.jobName];
if (nargin > 0)
parameters(res, fileprefix); % generates parameterfile (will need to add potfile)
jobstring = [res.indoExe,' ',res.parameterFile];

disp(['about to do: ',jobstring]);
[status, result] = system(jobstring);
res.indoOutput = result;
res.readIndo();
end
function run(obj)
indoexe = 'C:\mscpp\demo-dci\Release\demo-dci.exe';

file_prefix = [obj.dataPath, obj.filename];
parameters(res, fileprefix); % generates parameterfile (will need to add potfile)
jobstring = [indoexe,' ',res.parameterFile];

disp(['about to do: ',jobstring]);
[status, result] = system(jobstring);
obj.parse()
end
end % INDO constructor

end
function res = defaultConfig()
res.charge = 1;
res.norbs = 100;
res.nstates = 25;
res.field = [0,0,0];
res.potfile = '';
end
function res = get.osc(obj)
res = zeros(1,obj.nsci);
for i=1:obj.nsci
res(1,i) = (obj.esci(1,i)-obj.esci(1,1)) * ...
( obj.r(1,i,1)^2 + obj.r(1,i,2)^2 + obj.r(1,i,3)^2 );
( obj.r(1,i,1)^2 + obj.r(1,i,2)^2 + obj.r(1,i,3)^2 );
end
end
function res = get.rx(obj)
Expand All @@ -101,5 +79,5 @@
% or transition moment (istate ~= jstate)
res = reshape(obj.r(istate,jstate,:),[3,1]);
end
end % methods
end % class
end
end
89 changes: 12 additions & 77 deletions @Indo/parameters.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,86 +5,21 @@ function parameters(obj, fileprefix)
nstates= obj.config.nstates;
norbs = obj.config.norbs;

% if (nargin < 5)
% obj.field = [0.000 0.000 0.000];
% else
% obj.field = field;
% end
% if (nargin < 4)
% obj.charge = 0;
% else
% obj.charge = charge;
% end
% if (nargin < 3)
% obj.nstates = 25 ;
% else
% obj.nstates = nstates;
% end
% if (nargin < 2)
% obj.norbs = 100;
% else
% obj.norbs = norbs;
% end

%create the file
fid0 = fopen([obj.dataPath,'parameters.txt'],'wt');
fprintf(fid0, 'jobname = aaaaaaa\ncharge = bbbbbb\nnorbs = cccccc\nnstates = ddddddd\nefieldx = eeeeeee\nefieldy = fffffff\nefieldz = ggggggg');
fclose(fid0);

%if there is a potiential
if (~isempty(obj.config.potfile))
fid8 = fopen('parameters.txt','at');
fprintf(fid8,'\npot_file = xxxxxxxxx');
fclose(fid8);
end

% replacing the parameters
fid1 = fopen([obj.dataPath,'parameters.txt'],'r');
scan = textscan(fid1,'%s');
fclose(fid1);
scan = scan{1};
file = fileread([obj.dataPath,'parameters.txt']);

%jobname
job = find(ismember(scan,'jobname')==1);
scan(job+2);
t1 = strrep(file,scan{job+2},fileprefix);

%charge
chrg = find(ismember(scan,'charge')==1);
t2 = strrep(t1,scan{chrg+2},num2str(charge,'%i'));

fprintf(fid0, 'jobname = %s\n', fileprefix);
fprintf(fid0, 'charge = %i\n', charge);
fprintf(fid0, 'norbs = %i\n', norbs);
fprintf(fid0, 'nstates = %i\n', nstates);
fprintf(fid0, 'efieldx = %8.3f\n', fields(1));
fprintf(fid0, 'efieldy = %8.3f\n', fields(2));
fprintf(fid0, 'efieldz = %8.3f\n', fields(3));

%number of orbitals
norb = find(ismember(scan,'norbs')==1);
t3 = strrep(t2,scan{norb+2},num2str(norbs));

%number of states
nst = find(ismember(scan,'nstates')==1);
t4 = strrep(t3,scan{nst+2},num2str(nstates));

%xfield
xf = find(ismember(scan,'efieldx')==1);
t5 = strrep(t4,scan{xf+2},num2str(fields(1),'%8.3f'));
%yfield
yf = find(ismember(scan,'efieldy')==1);
t6 = strrep(t5,scan{yf+2},num2str(fields(2),'%8.3f'));
%zfield
zf = find(ismember(scan,'efieldz')==1);
t7 = strrep(t6,scan{zf+2},num2str(fields(3),'%8.3f'));

%pot file
potf = find(ismember(scan,'pot_file')==1);
potsize = size(potf,1);
if potsize == 1
t7 = strrep(t7,scan{potf+2},potfile);
end

%write in the file
fid2 = fopen([obj.dataPath,'parameters.txt'],'w');
fwrite(fid2, t7, 'char');
fclose('all');

if (~isempty(obj.config.potfile))
potfile = obj.config.potfile
fprintf(fid0,'pot_file = %s\n', potfile);
end

fclose(fid0);

end
25 changes: 18 additions & 7 deletions @Indo/readIndo.m → @Indo/parse.m
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
function readIndo(obj)
function parse(obj)

filename = [obj.dataPath,obj.jobName,'.ido'];
fid1 = fopen(filename);
if (fid1 == -1)
error(['in Indo.readIndo, could not find file: ',filename]);
% Will have utils.findText() issue errors for us as appropriate
issueErrors = true;
ido_file = [obj.dataPath, obj.filename, '.ido'];
fid1 = fopen(ido_file,'r');

if fid1 == -1
error(['in Indo.readIndo, could not find file: ',ido_file]);
fclose('all');
end

t1 = textscan(fid1,'%s');
fclose(fid1);

obj.norb = fread(fid1,1,'integer*4');
obj.aorbAtom = fread(fid1,[1,obj.norb],'integer*4');
obj.aorbAtom = obj.aorbAtom +1; % C++ starts count at 0 instead of 1
obj.aorbType = fread(fid1,[1,obj.norb],'integer*4');

ntest = fread(fid1,1,'integer*4');
if (ntest ~= obj.norb)
error('atomic and fock basis sizes differ');
error('atomic and fock basis sizes differ');
end

obj.nfilled = fread(fid1,1,'integer*4');
obj.hfE = fread(fid1,1,'real*8');
obj.orbE = fread(fid1,[1,obj.norb],'real*8');
Expand All @@ -31,4 +40,6 @@ function readIndo(obj)
obj.r(:,:,3) = fread(fid1,[obj.nsci,obj.nsci],'real*8');
temp = fread(fid1,[2,obj.nscibasis],'integer*4');
obj.ehsci = temp' +1; % +1 fixes the counting from 0 issue
obj.wfsci = fread(fid1,[obj.nscibasis,obj.nsci],'real*8');
obj.wfsci = fread(fid1,[obj.nscibasis,obj.nsci],'real*8');

end

0 comments on commit 6d43aba

Please sign in to comment.