⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 check.c

📁 药物开发中的基于结构的从头设计代码
💻 C
字号:
# include "process.h"

char *New_Bond_Viability_Check(Group &group_1, Group &group_2)
{
	// the new bond is between group_1.center and group_2.center 
	// the type of the new bond could be "1", "am", or "no".

	int swap;
	int num1_hetero, num2_hetero;
	Group tmp_group,g1,g2;
	char type[3];

	num1_hetero=num2_hetero=0;

	strcpy(type,"no");

	g1=group_1; g2=group_2;

	if(!strcmp(g1.center.type,"F")) strcpy(g1.center.type,"X");
	else if(!strcmp(g1.center.type,"Cl")) strcpy(g1.center.type,"X");
	else if(!strcmp(g1.center.type,"Br")) strcpy(g1.center.type,"X");
	else if(!strcmp(g1.center.type,"I")) strcpy(g1.center.type,"X");

	if(!strcmp(g2.center.type,"F")) strcpy(g2.center.type,"X");
        else if(!strcmp(g2.center.type,"Cl")) strcpy(g2.center.type,"X");
        else if(!strcmp(g2.center.type,"Br")) strcpy(g2.center.type,"X");
        else if(!strcmp(g2.center.type,"I")) strcpy(g2.center.type,"X");

	// rank group_1 and group_2 lexicographically for convenience  
	// they will be swapped back at the end of this function

	if(strcmp(g1.center.type,g2.center.type)>0)	
		{
		 tmp_group=g1; g1=g2; g2=tmp_group;
		 tmp_group=group_1; group_1=group_2; group_2=tmp_group;
		 swap=TRUE;
		}
	else swap=FALSE;

	num1_hetero=g1.num_hetero;
	num2_hetero=g2.num_hetero;

	if(!strcmp(g1.center.type,"C.2"))
		{
		 if(!strcmp(g2.center.type,"C.cat")) strcpy(type,"no");
		 else
		{
		 switch(g1.db_type)
			{
			 case 1:	// C=C
			 case 2:	// C=N
				{
				 if(g2.center.type[0]=='C') {strcpy(type,"1"); break;}
			 	 else if(g2.center.type[0]=='N') {strcpy(type,"no"); break;}
			 	 else if(g2.center.type[0]=='O') {strcpy(type,"no"); break;}
                               	 else if(g2.center.type[0]=='P') {strcpy(type,"no"); break;}
			 	 else if(g2.center.type[0]=='S') {strcpy(type,"no"); break;}
                               	 else if(g2.center.type[0]=='X') {strcpy(type,"no"); break;}
			 	 else {strcpy(type,"no"); break;}
				}
			 case 3:	// C=O
                                {
				 if(!strcmp(g2.center.type,"N.4")) {strcpy(type,"no"); break;}
				 else if(!strcmp(g2.center.type,"N.3"))	{strcpy(type,"no"); break;}
                                 else 
                                        {
                                         if(g2.center.type[0]=='C') {strcpy(type,"1"); break;}
                                         else if(g2.center.type[0]=='N')
                                        {
				 	 strcpy(type,"am"); 
					 strcpy(group_2.center.type,"N.am");
					 break;
					}
                                         else if(g2.center.type[0]=='O') {strcpy(type,"1"); break;}
                                         else if(g2.center.type[0]=='P') {strcpy(type,"no"); break;}
                                         else if(g2.center.type[0]=='S') {strcpy(type,"no"); break;}
                                         else if(g2.center.type[0]=='X') {strcpy(type,"no"); break;}
                                         else {strcpy(type,"no"); break;}
                                        }
                                }
			 case 4:	// C=S
                                {
                                 if(g2.center.type[0]=='C') {strcpy(type,"1"); break;}
                                 else if(g2.center.type[0]=='N') {strcpy(type,"no"); break;}
                                 else if(g2.center.type[0]=='O') {strcpy(type,"no"); break;}
                                 else if(g2.center.type[0]=='P') {strcpy(type,"no"); break;}
                                 else if(g2.center.type[0]=='S') {strcpy(type,"no"); break;}
                                 else if(g2.center.type[0]=='X') {strcpy(type,"no"); break;}
                                 else {strcpy(type,"no"); break;}
                                }
			 default: strcpy(type,"no"); break;
			}
		}
		}
	else if(!strcmp(g1.center.type,"C.3"))
                {
		 if(!strcmp(g2.center.type,"C.cat")) strcpy(type,"no");
		 else if(num1_hetero==0) strcpy(type,"1");
		 else
		{
		 if(g2.center.type[0]=='C') strcpy(type,"1"); 
		 else if(g2.center.type[0]=='N') strcpy(type,"no");
		 else if(g2.center.type[0]=='O') strcpy(type,"no");
		 else if(g2.center.type[0]=='P') strcpy(type,"no");
		 else if(g2.center.type[0]=='S') strcpy(type,"no");
		 else if(g2.center.type[0]=='X') strcpy(type,"no");
		 else strcpy(type,"no"); 
		}
                }
	else if(!strcmp(g1.center.type,"C.1"))	
		{
		 if(!strcmp(g2.center.type,"C.cat")) strcpy(type,"no");
		 else if(g2.center.type[0]=='C') strcpy(type,"1");
		 else if(g2.center.type[0]=='N') strcpy(type,"no"); 
		 else if(g2.center.type[0]=='O') strcpy(type,"no");
		 else if(g2.center.type[0]=='P') strcpy(type,"no");
		 else if(g2.center.type[0]=='S') strcpy(type,"no");
		 else if(g2.center.type[0]=='X') strcpy(type,"no");
		 else strcpy(type,"no"); 
		}
	else if(!strcmp(g1.center.type,"C.ar"))
		{
		 if(g1.num_nar==0) strcpy(type,"1");
		 else if(g1.num_nar==1||g1.num_nar==2) 
			{
			 if(g2.center.type[0]=='C') strcpy(type,"1");
			 else if(g2.center.type[0]=='N') strcpy(type,"no");
                 	 else if(g2.center.type[0]=='O') strcpy(type,"no");
                 	 else if(g2.center.type[0]=='P') strcpy(type,"no");
                 	 else if(g2.center.type[0]=='S') strcpy(type,"no");
			 else if(g2.center.type[0]=='X') strcpy(type,"no");
                 	 else strcpy(type,"no");
			}
		 else strcpy(type,"no");
		}
	else if(!strcmp(g1.center.type,"C.cat")) strcpy(type,"no");
	else if(!strcmp(g1.center.type,"N.4")||!strcmp(g1.center.type,"N.3")
		||!strcmp(g1.center.type,"N.am"))
                {
                 if(!strcmp(g2.center.type,"P.3")) strcpy(type,"1");
                 else if(!strcmp(g2.center.type,"S.o")) strcpy(type,"1");
                 else if(!strcmp(g2.center.type,"S.o2")) strcpy(type,"1");
                 else if(g2.center.type[0]=='N') strcpy(type,"no");
                 else if(g2.center.type[0]=='O') strcpy(type,"no");
                 else if(g2.center.type[0]=='P') strcpy(type,"no");
                 else if(g2.center.type[0]=='S') strcpy(type,"no");
                 else if(g2.center.type[0]=='X') strcpy(type,"no");
                 else strcpy(type,"no");
                }
	else if(g1.center.type[0]=='N')	// N.2, N.1, N.ar, N.pl3 
		{
		 if(g2.center.type[0]=='N') strcpy(type,"no");
		 else if(g2.center.type[0]=='O') strcpy(type,"no");
		 else if(g2.center.type[0]=='P') strcpy(type,"no");
		 else if(g2.center.type[0]=='S') strcpy(type,"no");
		 else if(g2.center.type[0]=='X') strcpy(type,"no");
		 else strcpy(type,"no");
		}
	else if(g1.center.type[0]=='O')
		{
		 if(!strcmp(g2.center.type,"P.3")) strcpy(type,"1");
		 else if(!strcmp(g2.center.type,"S.o")) strcpy(type,"1");
                 else if(!strcmp(g2.center.type,"S.o2")) strcpy(type,"1");
		 else if(g2.center.type[0]=='N') strcpy(type,"no");
                 else if(g2.center.type[0]=='O') strcpy(type,"no");
                 else if(g2.center.type[0]=='P') strcpy(type,"no");
                 else if(g2.center.type[0]=='S') strcpy(type,"no");
		 else if(g2.center.type[0]=='X') strcpy(type,"no");
                 else strcpy(type,"no");
		}
	else if(g1.center.type[0]=='P') strcpy(type,"no");
	else if(g1.center.type[0]=='S') strcpy(type,"no");
	else if(g1.center.type[0]=='X') strcpy(type,"no");
	else strcpy(type,"no");

      	if(swap==TRUE)
                {
                 tmp_group=group_1; group_1=group_2; group_2=tmp_group;
                }

        if(!strcmp(type,"1")) return "1";
        else if(!strcmp(type,"am")) return "am";
        else return "no";
}

int Group_Viability_Check(const Group &group)
{
	if(!strcmp(group.center.type,"C.3"))
		{
		 if(group.num_hetero<=2) return TRUE;
		 else return FALSE;
		}
	else if(!strcmp(group.center.type,"C.2"))
		{
		 if(group.num_hetero<=2) return TRUE;
		 else return FALSE;
		}
	else if(!strcmp(group.center.type,"C.1")) return TRUE;
	else if(!strcmp(group.center.type,"C.ar")) return TRUE;
	else if(!strcmp(group.center.type,"C.cat")) return TRUE;
	else if(!strcmp(group.center.type,"O.3"))
		{
		 if(group.num_hetero==0) return TRUE;
		 else return FALSE;
		}
	else if(!strcmp(group.center.type,"O.2")) return TRUE;
	else if(!strcmp(group.center.type,"O.co2")) return TRUE;
	else if(!strcmp(group.center.type,"N.4")||
		!strcmp(group.center.type,"N.3"))
		{
		 if(group.num_hetero==0) return TRUE;
		 else return FALSE;
		}
	else if(!strcmp(group.center.type,"N.2"))
		{
		 if(group.num_hetero==0) return TRUE;
		 else return FALSE;
		}
	else if(!strcmp(group.center.type,"N.1")) return TRUE;
	else if(!strcmp(group.center.type,"N.am"))
		{
		 if(group.num_hetero==0) return TRUE;
		 else return FALSE;
		}
	else if(!strcmp(group.center.type,"N.pl3")) 
		{
		 if(group.num_hetero==0) return TRUE;
		 else return FALSE;
		}
	else if(!strcmp(group.center.type,"N.ar")) 
		{
		 if(group.num_nar==0) return TRUE;
		 else return FALSE;
		}
	else if(!strcmp(group.center.type,"S.3")) 
		{
		 if(group.num_hetero==0) return TRUE;
		 else return FALSE;
		}
	else if(!strcmp(group.center.type,"S.2")) return TRUE;
	else if(!strcmp(group.center.type,"S.o")) return TRUE;
	else if(!strcmp(group.center.type,"S.o2")) return TRUE;
	else if(!strcmp(group.center.type,"P.3")) return TRUE;
	else if(!strcmp(group.center.type,"F"))
		{
		 if(group.num_hetero==0) return TRUE;
		 else return FALSE;
		}
	else if(!strcmp(group.center.type,"Cl"))
		{
		 if(group.num_hetero==0) return TRUE;
		 else return FALSE;
		}
	else if(!strcmp(group.center.type,"Br"))
		{
		 if(group.num_hetero==0) return TRUE;
		 else return FALSE;
		}
	else if(!strcmp(group.center.type,"I"))
		{
		 if(group.num_hetero==0) return TRUE;
		 else return FALSE;
		}
	else return FALSE;
}

int Molecule_Duplicate_Check(const Ligand &lig1, const Ligand &lig2)
{
	int i,j,mark;
	float d;

	if(lig1.weight!=lig2.weight) return FALSE;
	if(strcmp(lig1.formula,lig2.formula)) return FALSE;
	if(strcmp(lig1.index,lig2.index)) return FALSE;
	
	// first, check all the non-hydrogen atoms in the reverse order

	for(i=lig1.num_atom-1;i>=0;i--)
		{
		 if(lig1.atom[i].type[0]=='H') continue;

		 mark=FALSE;

	 	 for(j=lig2.num_atom-1;j>=0;j--)
		{
		 if(lig2.atom[j].type[0]=='H') continue;
		 else if(strcmp(lig1.atom[i].xtype, lig2.atom[j].xtype)) continue;
		 else
			{
			 d=Distance(lig1.atom[i].coor,lig2.atom[j].coor);
			 if(d>ATOM_OVERLAP_RANGE) continue;
			 else 
				{
				 mark=TRUE; 
				 break;
				}
			}
		}

		 if(mark==FALSE) return FALSE;
		}

	// second, check all the seed hydrogens in the reverse order

        for(i=lig1.num_atom-1;i>=0;i--)
                {
                 if(strcmp(lig1.atom[i].type,"H.spc")) continue;

                 mark=FALSE;

                 for(j=lig2.num_atom-1;j>=0;j--)
                {
                 if(strcmp(lig2.atom[j].type,"H.spc")) continue;
                 else
                        {
                         d=Distance(lig1.atom[i].coor,lig2.atom[j].coor);
                         if(d>ATOM_OVERLAP_RANGE) continue;
                         else
                                {
                                 mark=TRUE;
                                 break;
                                }
                        }
                }

                 if(mark==FALSE) return FALSE;
                }

	return TRUE;
}

int Conformation_Duplicate_Check(const Ligand &lig1, const Ligand &lig2)
{
	int i,j,mark;
	float d;

	for(i=lig1.num_atom-1;i>=0;i--)
	{
	 if(!strcmp(lig1.atom[i].type,"H")) continue;

	 mark=FALSE;

 	 for(j=lig2.num_atom-1;j>=0;j--)
		{
		 if(!strcmp(lig2.atom[j].type,"H")) continue;
		 else if(lig1.atom[i].valid!=lig2.atom[j].valid) continue;
		 else if(strcmp(lig1.atom[i].type,lig2.atom[j].type)) continue;
		 else
			{
			 d=Distance(lig1.atom[i].coor,lig2.atom[j].coor);
			 if(d>ATOM_OVERLAP_RANGE) continue;
			 else {mark=TRUE; break;}
			}
		}

	 if(mark==FALSE) return FALSE;	// not duplicate
	}

	return TRUE;	// duplicate
}

float Cal_Molecular_Similarity(const Ligand &lig1, const Ligand &lig2)
{
	int i,j,mark;
	int total,num_matched;
	float d;
	float sim=0.000;

	// count the total number of non-H atoms in the two molecules

	total=0;

	for(i=0;i<lig1.num_atom;i++)
		{
		 if(lig1.atom[i].valid==0) continue;
		 else if(lig1.atom[i].type[0]=='H') continue;
		 else total++;
		}

	for(i=0;i<lig2.num_atom;i++)
                {
                 if(lig2.atom[i].valid==0) continue;
                 else if(lig2.atom[i].type[0]=='H') continue;
                 else total++;
                }

	// count the number of matched non-H atoms in the two molecules

	num_matched=0;

	for(i=0;i<lig1.num_atom;i++)
		{
		 if(lig1.atom[i].valid==0) continue;
		 else if(lig1.atom[i].type[0]=='H') continue;

		 mark=FALSE;

		 for(j=0;j<lig2.num_atom;j++)
		{
		 if(lig2.atom[j].valid==0) continue;
                 else if(strcmp(lig1.atom[i].type,lig2.atom[j].type)) continue;

		 d=Distance(lig1.atom[i].coor,lig2.atom[j].coor);

                 if(d>ATOM_OVERLAP_RANGE) continue;
                 else {mark=TRUE; break;}	// atoms are matched
                }

		 if(mark==TRUE) num_matched++;
		}

	sim=(float)num_matched/(total-num_matched);
		 
	return sim;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -