4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * GRowing Old MAkes el Chrono Sweat
29 static char *SRCID_specbond_c
= "$Id$";
47 c
=toupper(fgetc(stdin
));
48 } while ((c
!= 'Y') && (c
!= 'N'));
61 static t_specbond
*get_specbonds(int *nspecbond
)
63 static char *sbfile
="specbond.dat";
66 char r1buf
[32],r2buf
[32],a1buf
[32],a2buf
[32],nr1buf
[32],nr2buf
[32];
72 nlines
= get_lines(sbfile
,&lines
);
77 for(i
=0; (i
<nlines
); i
++) {
78 if (sscanf(lines
[i
],"%s%s%d%s%s%d%lf%s%s",
79 r1buf
,a1buf
,&nb1
,r2buf
,a2buf
,&nb2
,&length
,nr1buf
,nr2buf
) != 9)
80 fprintf(stderr
,"Invalid line '%s' in %s\n",lines
[i
],sbfile
);
82 sb
[n
].res1
= strdup(r1buf
);
83 sb
[n
].res2
= strdup(r2buf
);
84 sb
[n
].nres1
= strdup(nr1buf
);
85 sb
[n
].nres2
= strdup(nr2buf
);
86 sb
[n
].atom1
= strdup(a1buf
);
87 sb
[n
].atom2
= strdup(a2buf
);
90 sb
[n
].length
= length
;
97 fprintf(stderr
,"%d out of %d lines of %s converted succesfully\n",
105 static void done_specbonds(int nsb
,t_specbond sb
[])
109 for(i
=0; (i
<nsb
); i
++) {
119 static bool is_special(int nsb
,t_specbond sb
[],char *res
,char *atom
)
123 for(i
=0; (i
<nsb
); i
++) {
124 if (((strcasecmp(sb
[i
].res1
,res
) == 0) &&
125 (strcasecmp(sb
[i
].atom1
,atom
) == 0)) ||
126 ((strcasecmp(sb
[i
].res2
,res
) == 0) &&
127 (strcasecmp(sb
[i
].atom2
,atom
) == 0)))
133 static bool is_bond(int nsb
,t_specbond sb
[],t_atoms
*pdba
,int a1
,int a2
,
134 real d
,int *nb
,bool *bSwap
)
137 char *at1
,*at2
,*res1
,*res2
;
139 at1
=*pdba
->atomname
[a1
];
140 at2
=*pdba
->atomname
[a2
];
141 res1
=*pdba
->resname
[pdba
->atom
[a1
].resnr
];
142 res2
=*pdba
->resname
[pdba
->atom
[a2
].resnr
];
144 for(i
=0; (i
<nsb
); i
++) {
146 if (((strcasecmp(sb
[i
].res1
,res1
) == 0) &&
147 (strcasecmp(sb
[i
].atom1
,at1
) == 0) &&
148 (strcasecmp(sb
[i
].res2
,res2
) == 0) &&
149 (strcasecmp(sb
[i
].atom2
,at2
) == 0))) {
151 if ((0.9*sb
[i
].length
< d
) && (1.1*sb
[i
].length
> d
))
154 if (((strcasecmp(sb
[i
].res1
,res2
) == 0) &&
155 (strcasecmp(sb
[i
].atom1
,at2
) == 0) &&
156 (strcasecmp(sb
[i
].res2
,res1
) == 0) &&
157 (strcasecmp(sb
[i
].atom2
,at1
) == 0))) {
159 if ((0.9*sb
[i
].length
< d
) && (1.1*sb
[i
].length
> d
))
166 static void rename_1res(t_atoms
*pdba
,int resnr
,char *nres
)
168 sfree(*pdba
->resname
[resnr
]);
169 *pdba
->resname
[resnr
]=strdup(nres
);
172 int mk_specbonds(t_atoms
*pdba
,rvec x
[],bool bInteractive
,
173 t_ssbond
**specbonds
)
176 t_ssbond
*bonds
=NULL
;
187 /* Initiate variables that will be exported */
189 sb
=get_specbonds(&nsb
);
196 for(i
=0;(i
<natoms
);i
++) {
197 if (is_special(nsb
,sb
,*pdba
->resname
[pdba
->atom
[i
].resnr
],
198 *pdba
->atomname
[i
])) {
199 specp
[nspec
] = pdba
->atom
[i
].resnr
;
207 /* distance matrix d[nspec][nspec] */
209 for(i
=0; (i
<nspec
); i
++)
212 for(i
=0; (i
<nspec
); i
++) {
214 for(j
=0; (j
<nspec
); j
++) {
216 d
[i
][j
]=sqrt(distance2(x
[ai
],x
[aj
]));
221 fprintf(stderr
,"Special Atom Distance matrix:\n");
222 for(b
=0; (b
<nspec
); b
+=MAXCOL
) {
223 fprintf(stderr
,"%8s","");
224 e
=min(b
+MAXCOL
, nspec
-1);
225 for(i
=b
; (i
<e
); i
++) {
226 sprintf(buf
,"%s%d",*pdba
->resname
[pdba
->atom
[sgp
[i
]].resnr
],
228 fprintf(stderr
,"%8s",buf
);
230 fprintf(stderr
,"\n");
231 e
=min(b
+MAXCOL
, nspec
);
232 for(i
=b
+1; (i
<nspec
); i
++) {
233 sprintf(buf
,"%s%d",*pdba
->resname
[pdba
->atom
[sgp
[i
]].resnr
],
235 fprintf(stderr
,"%8s",buf
);
237 for(j
=b
; (j
<e2
); j
++)
238 fprintf(stderr
," %7.3f",d
[i
][j
]);
239 fprintf(stderr
,"\n");
247 for(i
=0; (i
<nspec
); i
++) {
249 for(j
=i
+1; (j
<nspec
); j
++) {
251 if (is_bond(nsb
,sb
,pdba
,ai
,aj
,d
[i
][j
],
254 fprintf(stderr
,"Link Res%4d and Res%4d (y/n) ?",specp
[i
]+1,specp
[j
]+1);
258 fprintf(stderr
,"Linking Res%4d and Res%4d...\n",specp
[i
]+1,specp
[j
]+1);
262 /* Store the residue numbers in the bonds array */
263 bonds
[nbonds
].res1
= specp
[i
];
264 bonds
[nbonds
].res2
= specp
[j
];
265 bonds
[nbonds
].a1
= strdup(*pdba
->atomname
[ai
]);
266 bonds
[nbonds
].a2
= strdup(*pdba
->atomname
[aj
]);
268 rename_1res(pdba
,specp
[i
],sb
[index_sb
].nres2
);
269 rename_1res(pdba
,specp
[j
],sb
[index_sb
].nres1
);
272 rename_1res(pdba
,specp
[i
],sb
[index_sb
].nres1
);
273 rename_1res(pdba
,specp
[j
],sb
[index_sb
].nres2
);
281 for(i
=0; (i
<nspec
); i
++)
287 done_specbonds(nsb
,sb
);