Professional Documents
Culture Documents
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace xyz
{
class inputClass
{
static void Main(string[] args)
{
WeightedGraph inputobj = new WeightedGraph();
//Console.WriteLine("enter the option : \n1)input smiles notation\
n2)print adjacency matrix\n3)print implicit hydrogens\n4)print zagreb index\n");
Console.WriteLine("START ? (1/0)");
int option = Convert.ToInt32(Console.ReadLine());
string inputSmiles = "";
do{
Console.WriteLine("enter the option : \n1)input smiles notation\
n2)print adjacency matrix\n3)print implicit hydrogens\n4)print zagreb index\n");
option = Convert.ToInt32(Console.ReadLine());
switch (option)
{
case 1:
Console.WriteLine("ENTER THE INPUT SMILES NOTATION : ");
inputSmiles = Console.ReadLine();
if(!string.IsNullOrEmpty(inputSmiles))
{
inputobj.initiateVertex(inputSmiles);
inputobj.readSmiles(inputSmiles);
}
else
{
Console.WriteLine("ENTER A PROPER INPUT");
}
break;
case 2:
Console.WriteLine("ADJACENCY MATRIX : ");
inputobj.adjacencyMatrix(inputSmiles);
break;
case 3:
Console.WriteLine("IMPLICIT HYDROGEN COUNT : ");
inputobj.implicitHydrogenIndex(inputSmiles);
break;
case 4:
Console.WriteLine("ZAGREB INDEX : ");
inputobj.zagrebIndex(inputobj.adjacencyMatrix(inputSmiles));
break;
default:
Console.WriteLine("INVALID OPTION");
break;
}
Console.WriteLine("DO YOU WANT TO CONTINUE (1/0) :");
option = Convert.ToInt32(Console.ReadLine());
}while(option!=0);
}
}
class WeightedGraph
{
//INPUT SMILES
static int[] ElementIndexs;
static int elementCount=0;
//readonly
// Elements --> CONTAINS ALL THE < ELEMENT_NAME , VALENCE_ELECTRONS > PAIR
public static readonly Dictionary<string,int> Elements = new
Dictionary<string, int>()
{
{"H",1},{"He",2},{"Li",1},{"Be",2},{"B",3},{"C",4},{"N",5},
{"O",6},{"F",7},{"Ne",8},{"Na",1},{"Mg",2},{"Al",3},{"Si",5},
{"P",5},{"S",6},{"Cl",7},{"Ar",8},{"K",1},{"Ca",2},{"Sc",3},
{"Ti",4},{"V",5},{"Cr",6},{"Mn",7},{"Fe",8},{"Co",9},{"Ni",10},
{"Cu",11},{"Zn",12},{"Ga",3},{"Ge",3},{"As",5},{"Se",6},{"Br",7},
{"Kr",8},{"Rb",1},{"Sr",2},{"Y",3},{"Zr",4},{"Nb",5},{"Mo",6},
{"Tc",7},{"Ru",8},{"Rh",9},{"Pd",10},{"Ag",11},{"Cd",12},{"In",3},
{"Sn",4},{"Sb",5},{"Te",6},{"I",10},{"Xe",8},{"Cs",1},{"Ba",2},
{"La",3},{"Ce",4},{"Pr",5},{"Nd",6},{"Pm",7},{"Sm",8},{"Eu",9},
{"Gd",10},{"Tb",11},{"Dy",12},{"Ho",13},{"Er",14},{"Tm",15},{"Yb",16},
{"Lu",3},{"Hf",4},{"Ta",5},{"W",6},{"Re",7},{"Os",8},{"Ir",9},
{"Pt",10},{"Au",11},{"Hg",12},{"Pb",4},{"Bi",5},{"Po",6},
{"At",7},{"Rn",8},{"Fr",1},{"Ra",2},{"Ac",3},{"Th",4},{"Pa",5},
{"U",6},{"Np",7},{"Pu",8},{"Am",9},{"Cm",10},{"Bk",11},{"Cf",12},
{"Es",13},{"Fm",14},{"Md",15},{"No",16},{"Lr",3},{"Rf",4},{"Db",5},
{"Sg",6},{"Bh",7},{"Hs",8},{"Mt",9},{"Ds",10},{"Rg",11},{"Cn",12},
{"Nh",3},{"Fl",4},{"Mc",5},{"Lv",6},{"Ts",7},{"Og",8}
};
// bonds --> CONTAINS ALL THE < BOND , BOND_VALUE > PAIRS
public static readonly Dictionary<char,int> bonds = new Dictionary<char,
int>()
{
{'-',1},{'=',2},{'#',3},{'$', 4},{'.', 0},{':',1}
};
//CONSTRUCTOR
public WeightedGraph()
{
//INITIALIZING adjacencyList AND HydrogenCount AS EMPTY LISTS
this.adjacencyList = new Dictionary<int , Dictionary<int, int>>(){};
this.HydrogenCount = new Dictionary<int, int>(){};
}
for(int i=0;i<Matrix_size;i++)
{
if(check[i]!=0)
{
n=0;
for(int j=0;j<Matrix_size;j++)
{
if(check[j]!=0)
{
adjacencyMatrix[m,n]=array[i,j];
n++;
}
}
m++;
}
}
return adjacencyMatrix;
}
public void zagrebIndex(int[,] adjacencyMatrix)
{
if(adjacencyMatrix.GetLength(0)==adjacencyMatrix.GetLength(1))
{
int[] degreeOfVertices = new int[adjacencyMatrix.GetLength(0)];
int count=0;
for(int i=0;i<adjacencyMatrix.GetLength(0);i++)
{
count=0;
for(int j=0;j<adjacencyMatrix.GetLength(0);j++)
{
if(adjacencyMatrix[i,j]==1) count++;
}
degreeOfVertices[i]=count;
}
int M1 = 0;
for(int i=0;i<degreeOfVertices.Length;i++)
{
M1+=degreeOfVertices[i]*degreeOfVertices[i];
}
Console.WriteLine("M1 value : "+M1);
int M2=0;
double connindex=0;
for(int i=0;i<adjacencyMatrix.GetLength(0);i++)
{
// currSum=degreeOfVertices[i];
for(int j=0;j<adjacencyMatrix.GetLength(0);j++)
{
if(i<j)
{
if(adjacencyMatrix[i,j]==1)
{
M2+=degreeOfVertices[i]*degreeOfVertices[j];
connindex+=1/Math.Sqrt(degreeOfVertices[i]*degreeOfVertices[j]);
}
}
}
// Console.Write(M2+" ");
}
Console.Write("M2 value : "+M2);
Console.Write("\nrandic connectivity index : "+connindex+"\n");
}
else
{
Console.WriteLine("RE-DO ADJACENCY MATRIX");
}
}
for(int i=0;i<res.Length;i++)
{
//CHECK/LOGIC FOR BRANCH STRUCTURES IN INPUT SMILES NOTATION
if((res[i]==')'))
{
count--;
if(i!=res.Length-1)
{
if(bonds.ContainsKey(res[i+1]))
{
int bond = graph.findindexvalues(i,0,res);
graph.addEdge(i+2,arr[count],bond);
}
else if(Elements.ContainsKey(char.ToString(res[i+1])))
{
graph.addEdge(i+1,arr[count],1);
}
}
}
if((res[i]=='(')&&(res[i-1]!=')'))
{
if(char.IsLower(res[i-1]))
{
arr[count] = i-2;
}
else
{
arr[count] = i-1;
}
count++;
}
if((res[i]=='(')&&(res[i-1]==')'))
{
if(bonds.ContainsKey(res[i+1]))
{
int bond = graph.findindexvalues(i,0,res);
graph.addEdge(arr[count++],i+2,bond);
}
else
{
if(Elements.ContainsKey(char.ToString(res[i+1])))
{
graph.addEdge(arr[count++],i+1,1);
}
}
}
else if((res[i]=='(')&&(res[i-1]!=')'))
{
if(bonds.ContainsKey(res[i+1]))
{
int bond = graph.findindexvalues(i,0,res);
if(char.IsLower(res[i-1]))
{
graph.addEdge(i-2,i+2,bond);
}
else
{
graph.addEdge(i-1,i+2,bond);
}
}
else
{
if(char.IsLower(res[i-1]))
{
graph.addEdge(i-2,i+1,1);
}
else
{
graph.addEdge(i-1,i+1,1);
}
}
}
}
///CHECK/LOGIC FOR LINEAR TRAVERSAL AND BOND INITIALIZATION IN
INPUT SMILES NOTATION
if(i!=res.Length-1)
{
//cl=c
//clcl
//clc
if(Elements.ContainsKey(char.ToString(res[i])) && !
char.IsLower(res[i+1]))
{
if(Elements.ContainsKey(char.ToString(res[i+1])))
{
graph.addEdge(i,i+1,1);
}
// else if(char.IsLower(res[i+1]) && ((i+1)!=res.Length-1))
// {
// if(bonds.ContainsKey(res[i+2]))
// {
// graph.addEdge(i,i+3,bonds[res[i+2]]);
// }
// else
if(Elements.ContainsKey(char.ToString(res[i+2])))
// {
// graph.addEdge(i,i+2,1);
// }
// }
if(bonds.ContainsKey(res[i+1]))
{
if(Elements.ContainsKey(char.ToString(res[i+3])))
{
graph.addEdge(i,i+2,bonds[res[i+1]]);
}
}
}
else if(char.IsLower(res[i]) && res[i+1]!='(')
{
if(bonds.ContainsKey(res[i+1]))
{
graph.addEdge(i-1,i+2,bonds[res[i+1]]);
}
else
{
graph.addEdge(i-1,i+1,1);
}
}
if(char.IsDigit(res[i]))
{
if(res[i+1]!=')')
{
if(bonds.ContainsKey(res[i+1]))
{
graph.addEdge(nearestIndex(i,1),nearestIndex(i,0),bonds[res[i+1]]);
}
else
{
graph.addEdge(nearestIndex(i,1),nearestIndex(i,0),1);
}
}
}
}
}
//MAIN METHOD
// static void Main(string[] args)
// {
// //INITIATES THE GRAPH VERTICES AS INDEX OF THE ELEMENTS IN THE GI
// graph.initiateVertex(sb);
// //PRINT THE LIST RES-->CONTAINS INPUT SMILES IN CHARACTER ARRAY FORM
// Console.WriteLine("INPUT SMILES :"+sb+"\n");
// graph.readSmiles(sb);
// //IMPLICIT HYDROGEN INITIALIZATION
// // Console.WriteLine("\nIMPLICIT HYDROGEN COUNT\n");
// // graph.implicitHydrogenIndex(sb);
// }
}
}