Lewis structures

by sonone, Nov 11, 2020, 4:34 PM

As long awaited, I have completed a functional "package" to draw lewis structures! In this package, you can draw single electrons and electron pairs around an atom, single bonds, and double bonds. Here is the source code: Lewis structures v1.0
Here is a short tutorial:
Defining an atom:
To define an atom, you need to do three things: define the symbol, the position, and the angles that the electron groups are at (between 4 and 6). This is how you do it:
atom myatom=atom.atom("<symbol>",<position>,<angles in a comma separated list>);

Here is an example of A hydrogen atom at (0,0), with electron groups at 0, 90, 180, and 270:
atom myatom=atom.atom("H",(0,0),0,90,180,270);

To get these values back, do $\verb-myatom.symbol-$ to get the symbol, $\verb-myatom.place-$ to get the position, and $\verb-myatom.ep[<int>]-$ to get any of the electron group positions.

Placing the atom:
Now that you have your atom defined, place it by doing
myatom.pa();
This is essentially the same as
label(myatom.symbol, myatom,place);


Putting valence electrons on the atom:
There are two things you need to keep in mind when placing the electrons, the first is how many electron groups you have, and second how many electrons go in each (0, 1, or 2). Say I have my atom $\verb-myatom-$, and it has four electron groups, and I want 1 electron pair on each side. To do this, I simply put down
myatom.pe(2,2,2,2);
The first 2 corresponds to 0 degrees, the second 2 90 degrees, and so on. Also not that $\verb-.pe();-$ places the atom symbol too, so $\verb-.pa();-$ can sometimes be omitted.

Drawing single and double bonds:
To draw a single bond between atoms $\verb-myatom-$ and $\verb-youratom-$, you type
sb(myatom,youratom);
To edit the span of the bond, place a number between 0 an 1 inclusive after "youratom" like thus: $\verb-sb(myatom,youratom,.5);-$. You do the same for double bonds, except the function is $\verb-db();-$, not $\verb-sb();-$. Double bonding only differs in that you can edit the distance between the two bonds by adding one more number to the function (between 0 an 1 inclusive).
db(myatom, youratom, .7, .5);

Finally, here is a key to help remember the functions:
  • $\verb-pa-$ means "place atom"
  • $\verb-pe-$ means "place electron(s)"
  • $\verb-sb-$ means "single bond"
  • $\verb-db-$ means "double bond"

Here are a few things you can expect for the next version:
  • Triple bonds
  • Ion brackets
  • resonance structure arrow.

If there are any questions, comments, or suggestions, feel free to reply below!

Comment

4 Comments

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
Wow!! :coolspeak:

by player01, Nov 11, 2020, 4:46 PM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
Very nice! :)

by TheFlamingoHacker, Nov 12, 2020, 8:04 PM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
Cool! :D

by G.G.Otto, Nov 16, 2020, 12:32 AM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
For a cheat, do a triple bond by overlaying a double and a single bond :P :

[asy]size(70);
struct atom {
    string symbol;
    pair place;
    real[] ep;
    static atom atom(string symbol, pair place ... real[] ep){
        atom a=new atom;
        a.symbol=symbol;
        a.place=place;
        a.ep=ep;
        return a;
    }
    picture pap(){
    picture pic;
    label(pic,atom.symbol,atom.place);
    return pic;
    }
    void pa(){
        label(atom.symbol,atom.place);
    }
    void pe(... int[] v){
        atom.pa();
        for(int i=0; i<v.length; ++i){
            real[] ori=atom.ep;
            if(v[i]==1){
                    label(rotate(atom.ep[i], atom.place)*"$\cdot$", atom.place, 2*dir(atom.ep[i]));
            }
            if(v[i]==2){
                    label(rotate(atom.ep[i],atom.place)*"$:$", atom.place, 2*dir(atom.ep[i]));
            }
        }
    }
}
path cutoff(path a, real frac){
    return subpath(a,frac,1-frac);
}
path cutoff_begin(path a, real frac){
    return subpath(a,frac,0);
}
path cutoff_end(path a, real frac){
    return subpath(a,0,1-frac);
}
void sb(atom a, atom b, real f=.7){
    draw(cutoff(a.place--b.place,.5-f*.5));
}
void db(atom a, atom b, real l=.7, real h=.5){
    pair a1,a2,b1,b2;
    path vec=a.place--b.place;
    a1=rotate(-90,a.place)*point(cutoff_end(vec,1-h*.1),1);
    a2=rotate(90,a.place)*point(cutoff_end(vec,1-h*.1),1);
    b1=rotate(90,b.place)*point(cutoff_begin(vec,1-h*.1),0);
    b2=rotate(-90,b.place)*point(cutoff_begin(vec,1-h*.1),0);
    draw(cutoff(a1--b1,.5-l*.5)^^cutoff(a2--b2,.5-l*.5));
}
atom N1,N2;
N1=atom.atom("N",(0,0),0,180);
N2=atom.atom("N",(1,0),0,180);
N1.pe(0,2);
N2.pe(2,0);
sb(N1,N2);
db(N1,N2);
[/asy]

by sonone, Nov 17, 2020, 2:37 PM

Old material is mostly Asymptote, new material is calculator programming

avatar

sonone
Archives
+ April 2023
+ August 2022
+ April 2021
+ August 2020
Shouts
Submit
  • I still exist as well.

    by G.G.Otto, Aug 11, 2023, 2:44 AM

  • hello I'm still here lol

    by player01, Aug 6, 2022, 6:24 PM

  • [REVIVAL] I will start posting more calculator relating posts very soon. Even though school has been busy, I have been programming my calculators a decent amount, so I have a lot to share...

    by sonone, Feb 18, 2022, 10:29 PM

  • wow its been like 2.5 years since geo class

    by pieMax2713, Feb 4, 2022, 8:38 PM

  • @violin21, I've been very busy with school lately and haven't been able to add another lesson. I will when i get a free moment

    by sonone, Aug 19, 2021, 12:45 AM

  • ORZ CODER

    by samrocksnature, Aug 9, 2021, 9:57 PM

  • Could you make more Asymptote lessons on your "How to do Asymptote" blog?

    by violin21, Aug 9, 2021, 7:26 PM

  • You can take it, just C&P the CSS into your CSS area

    by sonone, Apr 17, 2021, 10:08 PM

  • how can we take the CSS if we have permission to not take it?

    by GoogleNebula, Apr 17, 2021, 5:22 PM

  • That is awesome!

    by sonone, Apr 15, 2021, 10:09 PM

  • I modified your dodecahedron and got:
    [asy]
    import three;
    import solids;
    size(300);
    currentprojection=orthographic(0,1.3,1.2);
    light(0,5,10);

    real phi=(sqrt(6)+1)/3;
    real g=(phi-1)/2;
    real s=1/2;
    real a=sqrt(1-phi*phi/4-g*g)+phi/2;

    triple[] d;
    d[0]=(phi

    by Andrew2019, Mar 26, 2021, 12:15 AM

  • Not too many, just changing the color here and there. I really like your CSS!

    by sonone, Feb 2, 2021, 10:35 AM

  • Nice!

    I see you're making changes to the CSS. :)

    by G.G.Otto, Feb 1, 2021, 9:26 PM

  • I'm learning Java now!

    by sonone, Feb 1, 2021, 5:56 PM

  • And I took part of it from CaptainFlint and then added a ton of modifications. ;)

    by G.G.Otto, Dec 1, 2020, 8:56 AM

98 shouts
Tags
About Owner
  • Posts: 2106
  • Joined: Aug 20, 2016
Blog Stats
  • Blog created: Mar 28, 2020
  • Total entries: 61
  • Total visits: 4975
  • Total comments: 146
Search Blog
a