简体   繁体   中英

alloy model for hydrocarbons

i need to model hydrocarbon structure using alloy basically i need to design alkane, alkene and alkyne groups i have created following signatures(alkene example)

sig Hydrogen{}
sig Carbon{}
sig alkenegrp{
    c:one Carbon,
    h:set Hydrogen,
    doublebond:lone alkenegrp
}
sig alkene{
    unit : set alkenegrp
}
fact{
    all a:alkenegrp|a not in a.doublebond.*doublebond
    all a:alkenegrp|#a.h=mul[#(a.c),2]
}
pred show_alkene{
    #alkene>1
}
run show_alkene

this works from alkene but when ever i try to design the same for alkane or alkyne by changing the fact like all a:alkynegrp|#ah=minus[mul[#(ac),2],2] it doesnt work. Can anyone suggest how do i implement it?

My problem statement is In Organic chemistry saturated hydrocarbons are organic compound composed entirely of single bonds and are saturated with hydrogen. The general formula for saturated hydrocarbons is C n H 2n+2 (assuming non-cyclic structures). Also called as alkanes. Unsaturated hydrocarbons have one or more double or triple bonds between carbon atoms. Those with double bond are called alkenes. Those with one double bond have the formula C n H 2n (assuming non-cyclic structures). Those containing triple bonds are called alkynes, with general formula C n H 2n-2 . Model hydrocarbons and give predicates to generate instances of alkane, alkene and alkyne. We have tried as:

sig Hydrogen{}
sig Carbon{}

sig alkane{
c:one Carbon,
h:set Hydrogen,
n:lone alkane
}

fact{
//(#h)=add [mul[(#c),2],2]
//all a:alkane|a not in a.*n
all a:alkane|#a.h=mul[#(a.c),2]
}
pred show_alkane(){}

run show_alkan

e

General formula for alkane is C n H 2n+2 ,for multiplication we can use mul inbuilt function but we can not write for addtion as we have to do C n H 2n+2 .What should we write so that it can work for alkane

I understand alkanes, alkenes, and alkynes a little better now, but I still don't understand why you think your Alloy model doesn't work.

To express the C n H 2n-2 constraint, you can certainly write what you suggested

all a:alkynegrp |
   #a.h = minus[mul[#(a.c), 2], 2]

The problem is only that in your alkane sig declaration you said c: one Carbon , which is going to fix the number of carbon atoms to exactly 1, so minus[mul[#(ac), 2], 2] is always going to evaluate to exactly 0. I assume you want to alloy for any number of carbons (since C n ) so you should change it from c: one Carbon to c: set Carbon . If you then run the show_alkane predicate, you should get some instances where the number of carbons is greater than 1 and thus, the number of hydrogens is greater than 0.

Also, for the alkane formula

all a:alkynegrp |
   #a.h = plus[mul[#(a.c), 2], 2]

the default scope of 3 will not suffice, because you will need at least 4 atoms of hydrogen when ac is non-empty, but you can fix that by explicitly giving a scope

run show_alkane for 8

If this wasn't the problem you were talking about, please be more specific about why you think "it doesn't work", ie, what is it that you expect Alloy to do and what is it that Alloy actually does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM