1 /*****
2 This file is part of the Babel Program
3 Copyright (C) 1992-96 W. Patrick Walters and Matthew T. Stahl
4 All Rights Reserved
5 All Rights Reserved
6 All Rights Reserved
7 All Rights Reserved
8
9 For more information please contact :
10
11 babel@mercury.aichem.arizona.edu
12 ------------------------------------------------------------------------
13
14 FILE : rdsybyl.c
15 AUTHOR(S) : Jussi Eloranta <eloranta@tukki.jyu.fi>
16 University of Jyvdskyld, Finland
17
18 Modified: 6-94 by Matthew Stahl to work with new method of
19 handling substructure files
20
21 Modified: 8-95 by Pat Walters to accomodate the modified mol2
22 format used by the NCI Molecules R' Us folks
23
24 DATE : 12-93
25 PURPOSE : routines to read an SYBYL MOL2 file
26 Supported record types (@<tripos>):
27 molecule, atom, bond. Others are igonred.
28
29 ******/
30
31 #include "bbltyp.h"
32
33 #define MOL "MOLECULE"
34 #define ATO "ATOM"
35 #define BON "BOND"
36
37 int
read_sybyl(FILE * file1,ums_type * mol)38 read_sybyl(FILE *file1, ums_type *mol)
39 {
40 char input_line[BUFF_SIZE];
41 char temp_title[BUFF_SIZE];
42 int i;
43 char temp_type[5];
44 int start,end,order;
45 int found_string = FALSE;
46 long int pos;
47 char bo_str[5];
48 double temp_num = 0.0;
49 int column;
50
51 while (fgets(input_line,sizeof(input_line),file1))
52 {
53 if ((input_line[0] == '@') && strstr(input_line,MOL))
54 {
55 found_string = TRUE;
56 break;
57 }
58 }
59
60 if (!found_string)
61 return(FALSE);
62
63 /* @<tripos>molecule record (6 data lines) */
64
65 /* molecule name */
66 fgets(input_line,sizeof(input_line),file1);
67 /*
68 if(sscanf(input_line, "%s",temp_title) != 1)
69 show_warning("Problem reading name of current file");
70 */
71 strcpy(temp_title,input_line);
72
73 /* # atoms, # bonds, # substructures, # features, # sets */
74 fgets(input_line,sizeof(input_line),file1);
75 if(sscanf(input_line, "%d %d", &Atoms, &Bonds) != 2)
76 {
77 show_warning("Problem reading number of Atoms and Bonds");
78 return(FALSE);
79 }
80
81 found_string = FALSE;
82 while (fgets(input_line, sizeof(input_line), file1))
83 {
84 if (strstr(input_line,"Energy"))
85 {
86 sscanf(input_line,"%*s%*s%lf",&temp_num);
87 }
88
89 if ((input_line[0] == '@') && strstr(input_line,ATO))
90 {
91 found_string = TRUE;
92 break;
93 }
94 }
95
96 if (!found_string)
97 {
98 show_warning("Unable to locate Atom Table in Sybyl MOL2 file");
99 Atoms = Bonds = 0;
100 return(FALSE);
101 }
102
103 ShowProgress(Atoms,"Reading Atoms");
104
105 initialize_ums(&mol);
106 initialize_residues(&mol);
107 strcpy(Title,temp_title);
108 strip_return(Title);
109 Energy = temp_num;
110
111 column = locate_input_type("SYB");
112 for (i = 1; i <= Atoms; i ++)
113 {
114 UpdateProgress();
115
116 strcpy(ResName(i),"UNK");
117 ResNum(i) = 1;
118 ChainNum(i) = 0;
119 fgets(input_line,sizeof(input_line),file1);
120 sscanf(input_line," %*s %s %lf %lf %lf %s %*s %*s %lf",
121 AtmId(i),
122 &X(i),
123 &Y(i),
124 &Z(i),
125 temp_type,
126 &Charge(i));
127 Atomic_number(i) = get_input_type(i,column,temp_type,Type(i),dummy);
128 }
129
130 found_string = FALSE;
131 while (fgets(input_line, sizeof(input_line), file1))
132 {
133 if ((input_line[0] == '@') && strstr(input_line,BON))
134 {
135 found_string = TRUE;
136 break;
137 }
138 }
139
140 if (!found_string)
141 {
142 show_warning("Unable to locate Bond Table in Sybyl MOL2 file");
143 release_ums(mol);
144 free(mol->residues);
145 Atoms = Bonds = 0;
146 return(FALSE);
147 }
148
149 for (i = 0; i < Bonds; i ++)
150 {
151 fgets(input_line,sizeof(input_line),file1);
152 sscanf(input_line,"%*d %d %d %s",&start,&end,bo_str);
153 uppercase(bo_str);
154 if (EQ(bo_str,"AR"))
155 order = 5;
156 else
157 if (EQ(bo_str,"AM"))
158 order = 1;
159 else
160 order = atoi(bo_str);
161 Connection(start,Valence(start)) = end;
162 BO(start,Valence(start)) = order;
163 Valence(start)++;
164 Connection(end,Valence(end)) = start;
165 BO(end,Valence(end)) = order;
166 Valence(end)++;
167 }
168
169 build_connection_table(mol);
170
171 pos = ftell(file1);
172
173 while (fgets(input_line,sizeof(input_line), file1) != NULL)
174 {
175 if ((input_line[0] == '@') && strstr(input_line,MOL))
176 {
177 fseek(file1,pos,0);
178 break;
179 }
180 }
181
182 type_hydrogens(mol);
183
184 return(TRUE);
185 }
186
187
188
189
190