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

📄 genmdeterministicgenerator.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
				 for(j=i+1;j<setOfBasicFragment.size();j++)				 {					 int temp1=parentID[i];					 int temp2=parentID[j];					 if(rowMatrix[i]==-1 && rowMatrix[j]==-1)					 {						 if(fragmentID[i]>33 && fragmentID[j]>33							 && rowMatrix[temp1]!=-1 && rowMatrix[temp2]!=-1						 	 && setOfStability[i]==setOfStability[j])						 	setOfStability[j]+=100;					 }				 }		 }		 /* get the category for this line*/		 count=1;		 for(i=step+1;i<setOfStability.length;i++)if(rowMatrix[i]==-1){line=i;break;}		 category[1]=setOfStability[line];		 for(i=step+1;i<setOfStability.length;i++)		 {			 if(setOfStability[i]!=0)			 {				 for(j=1;j<=count;j++)				 {					 if(rowMatrix[i]==-1)					 {						 temp=setOfStability[i]-category[j];						 if(temp==0)break;					 }					 else continue;				 }				 if(j>count)				 {					 count+=1;					 category[count]=setOfStability[i];				 }			 }		 }		 for(i=1;i<setOfStability.length;i++)			for(j=1;j<=count;j++)			{				if(rowMatrix[i]==-1)				{					temp=setOfStability[i]-category[j];					if(temp==0)equivalentClass[i]=j;				}			}		 equivalentClass[0]=count;		 for(i=0;i<setOfStability.length;i++)		 {			 setOfStability[i]=equivalentClass[i];		 }	 }	 /**	 * Force filling the left matrix at every step.	 *	 * @param	step			the line is filling	 * @param 	setOfBasicFragment	vector contains the set of basic fragment.	 * @param 	adjacencyMatrix		adjacency matrix of the given basic fragment.	 * @param	previousMatrix		matrix is used for tracing the change of adjacency matrix.	 * @return	the first line which is unfilled	 */	 public int forceFilling(int step,List setOfBasicFragment,int[][] adjacencyMatrix,int[][] previousMatrix)	 {		 /* 1.  Minimal forcing. The sum of filled elements of each unfilled row i->J(B)		  * 	is equal to the valence of the corresponding vertex.		  * 2.  Maximal forcing. The sum of all maximal multiplicity of edges of the Vi-th vertex, i->J(B)		  *	is equal to the valence of the vertex.		  */		  int i,j,iter,sum,bondOrder;		  int filledValence,unfilledValence,changedLine;		  do		  {			  changedLine=0;			  for(i=step;i<adjacencyMatrix.length;i++)			  {				  sum=0;				  unfilledValence=0;				  if(previousMatrix[i][i]>0)continue;				  for(j=0;j<adjacencyMatrix.length;j++)				  {					  if(adjacencyMatrix[i][j]>0)sum+=1;					  else if(adjacencyMatrix[i][j]==-1)unfilledValence+=1;				  }				  if(previousMatrix[i][i]==0 && unfilledValence==0)				  {					  previousMatrix[i][i]=step;				  }				  if(sum==((BasicFragment)(setOfBasicFragment.get(i))).getNumberOfFreeValence() && unfilledValence>0)				  {					  //Satisfy the minimal forcing, fill this line					  for(iter=0;iter<adjacencyMatrix.length;iter++)					  {						  if(adjacencyMatrix[i][iter]==-1)						  {							  adjacencyMatrix[i][iter]=0;							  previousMatrix[i][iter]=step;							  adjacencyMatrix[iter][i]=0;							  previousMatrix[iter][i]=step;						  }					  }					  previousMatrix[i][i]=step;					  changedLine+=1;				  }			  }		  	/* maximal forcing. */			for(i=step;i<adjacencyMatrix.length;i++)			{				sum=0;				filledValence=0;				if(previousMatrix[i][i]>0)continue;				for(j=0;j<adjacencyMatrix.length;j++)				{				  	if(adjacencyMatrix[i][j]==-1)sum+=1;					else  if(adjacencyMatrix[i][j]>0)filledValence+=1;				}				if(previousMatrix[i][i]==0 && sum==0)				  {					  previousMatrix[i][i]=step;				  }				  if(sum==(((BasicFragment)(setOfBasicFragment.get(i))).getNumberOfFreeValence()-filledValence) && sum>0)				  {					  bondOrder=((BasicFragment)(setOfBasicFragment.get(i))).getAttribute();					  //Satisfy the maximal forcing, fill this line					  for(iter=0;iter<adjacencyMatrix.length;iter++)					  {						  if(adjacencyMatrix[i][iter]==-1)						  {							  adjacencyMatrix[i][iter]=bondOrder;							  previousMatrix[i][iter]=step;							  adjacencyMatrix[iter][i]=bondOrder;							  previousMatrix[iter][i]=step;						  }					  }					  previousMatrix[i][i]=step;					  changedLine+=1;				  }			}		  }while(changedLine>0);		  /* find the first unfilled line*/		  for(i=step;i<adjacencyMatrix.length;i++)			  for(j=0;j<adjacencyMatrix.length;j++)if(adjacencyMatrix[i][j]==-1)return i;		  return adjacencyMatrix.length;	 }	 /**	  * Check admissibility of the matrix.	  * Details see Sergey G. Molodtsov, Computer-Aided Generation of Molecular Graphs,	  * Match, 30(213),1994	  *	  * @param	step			the line is filling.	  * @param	setOfBasicFragment	set of basic fragment	  * @param	adjacencyMatrix		adjacency matrix	  * @return	a boolean value whether this line could pass adissibility or not	  */	 public boolean checkAdmissibility(int step,List setOfBasicFragment,int[][] adjacencyMatrix)	 {		 for(int i=step;i<adjacencyMatrix.length;i++)		 {			  int sum=0;			  int unfilledValence=0;			  {				  for(int j=0;j<adjacencyMatrix.length;j++)				  {					  if(adjacencyMatrix[i][j]>0)sum+=1;					  if(adjacencyMatrix[i][j]==-1)unfilledValence+=1;				  }				if(sum>((BasicFragment)(setOfBasicFragment.get(i))).getNumberOfFreeValence()){return false;}				  if(unfilledValence<(((BasicFragment)(setOfBasicFragment.get(i))).getNumberOfFreeValence()-sum) && unfilledValence>=0)				  {					 return false;				  }			  }		  }		  return true;	 }	 /**	  * Check constraint of the matrix. Currently, there is only connectivity test.	  * Later, there might be other tests.	  *	  * @param	step			the line is filling.	  * @param	setOfBasicFragment	set of basic fragment	  * @param	adjacencyMatrix		adjacency matrix	  * @param	ac			atomContainer of the node set, not used now	  * @return	a boolean value whether this adjacency matrix pass  the constraint check or not	  */	 public boolean checkConstraint(int step,List setOfBasicFragment,int[][] adjacencyMatrix, IAtomContainer ac)	 {		 int i,j,partialSum,totalSum,decomposedNumber;		 //boolean isConnectivity;		 boolean[] isVisited=new boolean[adjacencyMatrix.length];		 int[] isDecomposed=new int[adjacencyMatrix.length];		 int[] parentID=new int[adjacencyMatrix.length];		 for(i=0;i<adjacencyMatrix.length;i++)		 {			 isVisited[i]=false;			 isDecomposed[i]=0;			 parentID[i]=0;		 }		 /* check connectivity first. This time, it is substructure or structure*/		 if(step==1)return true;		 else if(step==adjacencyMatrix.length)		 {			 decomposedNumber=0;			 for(i=0;i<adjacencyMatrix.length;i++)			 {				 if(((BasicFragment)(setOfBasicFragment.get(i))).getID()>33)				 {					 isDecomposed[i]=((BasicFragment)(setOfBasicFragment.get(i))).getID();					 parentID[i]=((BasicFragment)(setOfBasicFragment.get(i))).getParentID();					 decomposedNumber+=1;				 }			 }			 if(decomposedNumber>0)			 {				 for(i=0;i<adjacencyMatrix.length-1;i++)					 for(j=i+1;j<adjacencyMatrix.length;j++)						 if(isDecomposed[i]!=isDecomposed[j] && parentID[i]==parentID[j] &&							 i!=j && adjacencyMatrix[i][i]==0 && adjacencyMatrix[j][j]==0)						 {							 adjacencyMatrix[i][j]=10;							 adjacencyMatrix[j][i]=10;							 adjacencyMatrix[i][i]=10;							 adjacencyMatrix[j][j]=10;						 }			 }			 DFSM(adjacencyMatrix,0,isVisited);			 if(decomposedNumber>0)			 {				 for(i=0;i<adjacencyMatrix.length;i++)					 for(j=0;j<adjacencyMatrix.length;j++)						 if(adjacencyMatrix[i][j]==10)adjacencyMatrix[i][j]=0;			 }			 for(i=0;i<adjacencyMatrix.length;i++)if(!isVisited[i])return false;			 return true;			// }		 }		 else		 {			 decomposedNumber=0;			 for(i=0;i<adjacencyMatrix.length;i++)			 {				 if(((BasicFragment)(setOfBasicFragment.get(i))).getID()>33)				 {					 isDecomposed[i]=((BasicFragment)(setOfBasicFragment.get(i))).getID();					 parentID[i]=((BasicFragment)(setOfBasicFragment.get(i))).getParentID();					 decomposedNumber+=1;				 }			 }			 if(decomposedNumber>0)			 {				 for(i=0;i<adjacencyMatrix.length-1;i++)					 for(j=i;j<adjacencyMatrix.length;j++)						  if(isDecomposed[i]!=isDecomposed[j] && parentID[i]==parentID[j] &&							 i!=j && adjacencyMatrix[i][i]==0 && adjacencyMatrix[j][j]==0)						{							 adjacencyMatrix[i][j]=10;							 adjacencyMatrix[j][i]=10;							 adjacencyMatrix[i][i]=10;							 adjacencyMatrix[j][j]=10;						 }			 }			 DFSM(adjacencyMatrix,0,isVisited);			 if(decomposedNumber>0)			 {				 for(i=0;i<adjacencyMatrix.length;i++)					 for(j=0;j<adjacencyMatrix.length;j++)					 	if(adjacencyMatrix[i][j]==10)adjacencyMatrix[i][j]=0;			 }			 partialSum=0;			 totalSum=0;			 for(i=0;i<step;i++)			 {				 if(isVisited[i])partialSum+=1;			 }			 for(i=0;i<adjacencyMatrix.length;i++)			 {				 if(isVisited[i])totalSum+=1;			 }			 if(partialSum==step && partialSum==totalSum)return false;			 else if(totalSum==adjacencyMatrix.length)return true;			 else return true;		 }	 }	 /**	  * Get the next WCF (weakly canonical complement).	  * Details see Sergey G. Molodtsov, Computer-Aided Generation of Molecular Graphs,	  * Match, 30(213),1994	  *	  * @param	setOfBasicFragment	set of basic fragment	  * @param	step			the step of the generation	  * @param	rowMatrix		the row which contains the filling line	  * @param	adjacencyMatrix		adjacency matrix	  * @param	previousMatrix		matrix to trace the change of adjacency matrix	  * @param	parentID		array mainly used for complex bond	  * @return	a boolean value whether there is next WCF or not	  *	  */	 public boolean getNextWCF(List setOfBasicFragment,int step,int[] rowMatrix,int[][] adjacencyMatrix,int[][] previousMatrix,int[] parentID)	 {		 int i,j,iter,existBond,leftBond,totalBond,changedCategory,sum; // changedFilledValue,nextNonZeroElement		 int bondOrder;		 int[] setOfStability;		 int[] previousLine;		 int[] category;		 int[] previousFilledValue;		 int[] currentFilledValue;		 setOfStability=new int[rowMatrix.length];		 previousLine=new int[rowMatrix.length];		 category=new int[rowMatrix.length];		 previousFilledValue=new int[rowMatrix.length];		 currentFilledValue=new int[rowMatrix.length];		 for(i=step;i<rowMatrix.length;i++)		 {			 previousLine[i]=rowMatrix[i];		 }		 iter=0;		 for(i=0;i<rowMatrix.length;i++)		 {			 rowMatrix[i]=adjacencyMatrix[step][i];			 if(rowMatrix[i]==-1)iter+=1;		 }		 getSetOfStability(setOfBasicFragment,step,rowMatrix,adjacencyMatrix,setOfStability,parentID);		 existBond=0;		 for(i=0;i<adjacencyMatrix.length;i++)if(rowMatrix[i]>0)existBond+=1;		 totalBond=((BasicFragment)(setOfBasicFragment.get(step))).getNumberOfFreeValence();		 bondOrder=((BasicFragment)(setOfBasicFragment.get(step))).getAttribute();		 leftBond=totalBond-existBond;		 iter=1;		 while(iter<=setOfStability[0])		 {			 for(i=1;i<rowMatrix.length;i++)			 {				 if(setOfStability[i]==iter)category[iter]+=1;				 if(setOfStability[i]==iter)					 if(previousLine[i]>0)previousFilledValue[iter]+=1;			 }			 iter+=1;		 }		 category[0]=setOfStability[0];		 changedCategory=0;		 for(i=category[0];i>=1;i--)if(previousFilledValue[i]!=0){changedCategory=i;break;}		 /* judge mininal WCF*/		 if(changedCategory==category[0])		 {			 if(previousFilledValue[category[0]]< category[changedCategory] && previousFilledValue[category[0]]==leftBond)				 return false;			 else if(previousFilledValue[category[0]]==category[changedCategory])			 {				 sum=0;				 for(i=category[0];i>=1;i--)				 {					 sum+=previousFilledValue[i];					 if(previousFilledValue[i]==category[i] && sum<leftBond)continue;					 if(sum==leftBond)return false;					 break;//non-termination				 }			 }		 }		 /*get next WCF*/		 if(changedCategory!=category[0])		 {			 for(i=1;i<=category[0];i++)			 {				 if(i<changedCategory)currentFilledValue[i]=previousFilledValue[i];				 else if(i==changedCategory)currentFilledValue[i]=previousFilledValue[i]-1;				 else if(i==(changedCategory+1))currentFilledValue[i]=1;			 }		 }		else if(changedCategory==category[0] && (previousFilledValue[changedCategory]<category[changedCategory]||previousFilledValue[changedCategory-1]==0))		{			while(previousFilledValue[changedCategory-1]==0)changedCategory-=1;			sum=0;			for(i=1;i<(changedCategory-1);i++)			{				currentFilledValue[i]=previousFilledValue[i];				sum+=currentFilledValue[i];			}			currentFilledValue[changedCategory-1]=previousFilledValue[changedCategory-1]-1;			sum+=currentFilledValue[changedCategory-1];			iter=changedCategory;			 while(leftBond>sum)			  {				 currentFilledValue[iter]=leftBond-sum;				 if(currentFilledValue[iter]>category[iter] && iter<category[0])				 {					 currentFilledValue[iter]=category[iter];					 sum+=currentFilledValue[iter];					 iter+=1;					 continue;				 }				 else break;			  }		}		else if(changedCategory==category[0]&& previousFilledValue[changedCategory]==category[changedCategory] &&			previousFilledValue[changedCategory-1]!=0 && previousFilledValue[changedCategory-1]<category[changedCategory-1])		{			while(previousFilledValue[changedCategory-2]==0)changedCategory-=1;			sum=0;			for(i=1;i<(changedCategory-2);i++)			{				currentFilledValue[i]=previousFilledValue[i];				sum+=currentFilledValue[i];			}			currentFilledValue[changedCategory-2]=previousFilledValue[changedCategory-2]-1;

⌨️ 快捷键说明

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