/********** *********** checksmell(perfume,flower). check chemical formula electrondistribution - find all combinations of atoms in molecule %% findatomiccombinations(Atoms,Bonds,Combinations) %% findatomiccombinations([[1,h],[2,h]],[[1,2,single]],Combinations). %% Combinations = [[h,h,single]] %% forget, because will work out individually, for each atomic combination findatomiccombinations(Atoms,[Bonds|Bonds],Combinations) :- Bonds = [AtomID1, AtomID2, Type], atom(AtomID1,Atoms,Atom1), atom(AtomID2,Atoms,Atom2) atom(AtomID,Atoms,Atom), Atom1 = [AtomID, Atom], member(Atom1, Atoms). - check electron distributions 1. distribute electrons 2. check number of bonds match number of lone pairs 3. check molecules match 1. distribute electrons **/ %%distributeelectrons([[1,'A'],[2,'A']],Atoms). %%Atoms=[[1,'A',1],[2,'A',1]]. distributeelectrons([],Atoms,Atoms). distributeelectrons(Atoms1,Atoms2,Atoms3) :- Atoms1 = [Atom1 | Atoms4], Atom1 = [Number, Name], electrons(Name, Electrons), Atom2 = [Number, Name, Electrons], append(Atoms2,[Atom2],Atoms5), distributeelectrons(Atoms4,Atoms5,Atoms3). electrons('A',1). electrons('B',2). electrons('C',3). electrons('D',4). /** *** Number -> BondNumber 2. check number of bonds match number of lone pairs**/ %% checkbonds1([[1,2,single]],[[1,'A',1],[2,'A',1]]). checkbonds1([],_,_). checkbonds1(Bonds1,Atoms1,Atoms2) :- Bonds1 = [Bond | Bonds2], Bond = [Number1, Number2, Number3], %%electronnumber(Number1,Atoms1,Number4), %%electronnumber(Number2,Atoms1,Number5), checkbonds2(Number3,Number1,Number2,Atoms1,Atoms3), checkbonds1(Bonds2,Atoms3,Atoms2). checkbonds2(single,Number1,Number2,Atoms1,Atoms2) :- decrement(Number1,Atoms1,Atoms3,Number3), decrement(Number2,Atoms3,Atoms4,Number4), decrement(Number1,Atoms1,Atoms2,Number2) :- member(Atom,Atoms1), Atom = [Number1, _, Number3), Number3 > 0, Number2 is Number3 - 1. /** 3. check molecules match checksamemolecules([[1,h],[2,h]],[[1,2,single]],[[1,h],[2,h]],[[1,2,single]]). check with each combo of atoms **/ checksamemolecules(Atoms1,Bonds1,Atoms2,Bonds2) :- %% collect all atoms for each molecule checksamemolecules(1,Atoms1,Bonds1,Bonds1,Atoms2,Bonds2,Bonds2). checksamemolecules(CurrAtom,Atoms1,Bonds1,Bonds2,Atoms2,Bonds3,Bonds4) :- collectatoms(Bonds1,Atoms1,Atoms2) :- Bonds1 = [Bond | Bonds2], Bond = [Atom1, Atom2, _BondNumber], appendatom(Atoms1,A