File: createMolproLibFileForGabedit.c

package info (click to toggle)
gabedit 2.4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 17,236 kB
  • sloc: ansic: 294,923; cpp: 2,081; sh: 1,111; makefile: 507; csh: 181
file content (157 lines) | stat: -rw-r--r-- 3,562 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define NATOMS 120
#define BSIZE 1024

/*************************************************************************************************************************/
typedef enum
{
  FALSE = 0,
  TRUE = 1
} MyBoolean;

/*************************************************************************************************************************/
typedef struct _Atom
{
	char Symb[5];
	int nbas;
	char** basis;
	int* orb[21];/*
				 ecp = 0, s = 1,  p = 2,  d = 3,  f = 4,  g = 5,  h  = 6,  i = 7,  j = 8,  k = 9,  l = 10
			      	          S = 11, P = 12, D = 13, F = 14, G = 15, H  = 16, I = 17, J = 18, K = 19, L =20
			  */
}Atom;
/*************************************************************************************************************************/
int get_num_orb(char *orb)
{
	char allorb[21] = {'E','s','p','d','f','g','h','i','j','k','l',
			 'S','P','D','F','G','H','I','J','K','L'};
	int i=0;

	for(i=0;i<21;i++)
		if(orb[0] == allorb[i]) return i;
	return -1;
}
int main()
{
	FILE* fin;
	FILE* fout;
	Atom *Atoms = malloc(NATOMS*sizeof(Atom));
	int natoms = 0;
	char symb[5];
	char orbecp[5];
	char bas[30];
	char t[BSIZE];
	int i=0;
	int numorb= -1;

	fin = fopen("libmol.bas","r");
	if(!fin)
	{
		printf("=================================================================\n");
		printf("I can not open libmol.bas\n");
		printf("For create this file, On the machine where Molpro is installed\n");
		printf("type the following order : libmol > libmol.bas\n");
		printf("libmol is a program delivered with Molpro software\n");
		printf("=================================================================\n");
		return 1;
	}
	while(!feof(fin))
	{
        	int E = FALSE;
		int j = 0;
		if(!fgets(t,BSIZE,fin)) break;
		if(sscanf(t,"%s %s %s",symb,orbecp,bas) != 3)
		{
			printf("Error : readding of data file\n");
			break;
		}
		for(i=0;i<natoms;i++)
		{
			if( strcasecmp(symb,Atoms[i].Symb) == 0)
			{
				int Ok = FALSE;
				int j;

				for(j=0;j<Atoms[i].nbas;j++)
				{
					if( strcmp(bas,Atoms[i].basis[j]) == 0)
					{
						numorb = get_num_orb(orbecp);
						if(numorb>=0)
							Atoms[i].orb[numorb][j] = 1;
						Ok = TRUE;
						break;
					}
				}
	
				if(!Ok)
				{
					int n = Atoms[i].nbas;
					Atoms[i].basis = realloc(Atoms[i].basis,(n+1)*sizeof(char*)); 
					for(j=0;j<21;j++)
					{
						Atoms[i].orb[j] = realloc(Atoms[i].orb[j],(n+1)*sizeof(int)); 
						Atoms[i].orb[j][n] = 0;
					}

					Atoms[i].basis[n] = strdup(bas);
					numorb = get_num_orb(orbecp);
					if(numorb>=0)
						Atoms[i].orb[numorb][n] = 1;
					(Atoms[i].nbas)++;
				}
				E = TRUE;
				break;	
			}
		}

		if(E) continue;

		i = natoms;

	        sprintf(Atoms[i].Symb,"%s",symb);
		Atoms[i].basis = malloc(sizeof(char*));
		for(j=0;j<21;j++)
		{
			Atoms[i].orb[j] = malloc(sizeof(int)); 
			Atoms[i].orb[j][0] = 0;
		}

        	Atoms[i].basis[0] = strdup(bas);
		numorb = get_num_orb(orbecp);
		if(numorb>=0)
			Atoms[i].orb[numorb][0] = 1;
      		  Atoms[i].nbas = 1;       
		natoms++;
	}
	fclose(fin);

	fout = fopen("molprobasis","w");
	if(!fout)
	{
		printf("I can not open molprobasis\n");
		return 1;
	}
	fprintf(fout,"Natoms = %d\n",natoms);
	for(i=0;i<natoms;i++)
	{
		int j=0;
		fprintf(fout,"Atom %s\n",Atoms[i].Symb);
		fprintf(fout,"%d\n",Atoms[i].nbas);
		for(j=0;j<Atoms[i].nbas;j++)
		{
			int k = 0;
			fprintf(fout,"%s",Atoms[i].basis[j]);
			for(k=0;k<21;k++)
				fprintf(fout," %d ",Atoms[i].orb[k][j]);
			fprintf(fout,"\n");
		}
	}
	fclose(fout);

	return	0;
	
}