"I once had a sparrow alight upon my shoulder for a moment... and I felt that I was more distinguished by that circumstance than I should have been by any epaulet I could have worn." -Thoreau
Showing posts with label nerd girl. Show all posts
Showing posts with label nerd girl. Show all posts

Sunday, August 26, 2012

Lessons from Computational Chemistry!


Hello, hello!

If anyone could explain to me how there is less than a week left of the long month of August, I would be most grateful.

I find myself back in my SoCal home... somewhat disoriented, excited, distraught, happy, lonely, scared, nostalgic... yearning at turns for comfiness&coziness and for excitement&adventure.
Mostly, I feel very unprepared about the unreal reality that, granted the benevolence of the Fates, I shall be leaving for Budapest in five days(!!).

The last two weeks or so since I last wrote were a little crazy, and quite wonderful.

Research ended nicely- and I shall attempt to provide an explanation of the exciting things I was doing! :]
Brace yourself, dear Reader. We are in for a trip!

So... Our simulations for LTA were failing quite miserably, and we believe the cause (or one major cause, anyway) to be the presence of a dipole in our unit cell structure (we'll talk more about dipoles later).

Backing up a bit. My work was with zeolites. Zeolites are pretty crystals, which means they have repetitive structural units-- aka unit cells. What this means is that you can tile a bunch of unit cells together to get a zeolite-- this not only contributes to the beauty of staring at atom-level pictures of zeolites (which I am fond of doing), but it also means that we can save ourselves time by exploiting the symmetry of the system. Look! A picture!
A unit cell is here boxed in red.



In order to run our simulations, we tile together something like 12 to 36 unit cells (pretending we actually have a 2D system, we can see 4 unit cells in the picture) because 1) we can't afford to try to model a super large system and 2) we can use tricks to make the system seem bigger than it actually is (to get more realistic results).
[For those more mathematically inclined, refer to periodic boundary conditions (we’re mapping onto a torus!!)]

We have essentially two versions of the code that controls our simulations-- one which uses Ewald summation to deal with interactions between charges, and one which does not. For the purposes of this discussion, it doesn’t matter what Ewald does. I’m just using it to differentiate between two different ways of running the simulation. The important thing here is that the version of the code which uses Ewald (which is the version we were interested in) needs the coordinates of the unit cell to be such that the center is (0,0). The other important thing is that using Ewald requires that the unit cell not have a dipole.

For those of us who do not remember what a dipole is, dipoles emerge when you have an imbalance of charge. To use my professor's example from intro chem, think of elephants pulling on a rope tied to a tree. If you have two elephants pulling just as hard in exactly opposite directions, the tree will not fall over. If one is pulling harder than the other, or if they’re pulling in a way that the forces they are exerting on the tree don’t cancel out, the tree will fall over. So having a dipole รจ the tree falls over.
In this case, we don’t want the tree to fall over.

So we want a structure centered at zero. However, the crystal structure does not start off this way. Instead, it starts off such that the (0,0) point is at the lower left corner.

Original, Uncentered LTA Crystal Structure


Ewald thinks that this is not okay, and so there is a function in the Ewald code that “centers” the structure to make sure that the structure is the way that it likes it.
At least theoretically.

Problem: Somehow or another this function was not working quite properly. The original crystal structure has no dipole (we know this because when we use the non-Ewald version of our code, all is well, and when we use Ewald, things go terribly wrong), but after centering it, it does. This suggests that something funky is going on... and the crystal is not, in fact, being centered properly.

 So, my job for the last few days of summer research was to understand what was going on with the centering process— with the goal of modifying the crystal structure such that it is centered (and dipole-less) to begin with, and undergoes no modification when put through the centering function in the Ewald code.

Summary:
How things are--
 Crystal structure (no dipole, uncentered) --[Ewald centering function]--> Weird, dipole-carrying structure
How I want things to be--
 Modified, centered structure –[Ewald centering function]--> Still nice and centered structure

Alright, so now the problem-solving part.

First, some terminology. 
Because I can’t look at the structure in 3D very easily, I was looking at projections onto a plane.
So what does this mean?

Imagine you’re looking at a cube. This is 3D. Now imagine you start to push on the top of the cube and the inside of the cube kind of collapses so you can flatten the cube into the ground, and you’re just left with…. 
A square, yes? (Yes.) That square is the projection of the cube onto a plane.

Or, if we started off with a delicious donut and for some reason decided to squash it down instead of eat it, we’d get two concentric circles as the projection onto what I shall arbitrarily term the xy plane:

A torus (or mathematical donut)
    
Projection of torus onto plane


[Of course, there’s no reason why you must squish your donut down towards the floor. You could also think of squashing it against a wall—what would that look like?]

Now that we have that, the pictures we saw earlier were the projections of the crystal structure onto the xy plane. And, again, here is the original, uncentered structure:



And here is the output of the centering function (again, projection onto the xy plane), which then gets used in the simulation:
Centered structure.
Red = oxygen atoms, blue = silicon atoms



See how we’re now “centered” at zero?

However, there is a problem, and it is one which would clearly give rise to a dipole. Remember, we want things to be nice and symmetric (such that for any elephant pulling in one direction, there is another elephant pulling just as hard in the opposite direction to balance things out)—but they are not!

(The problem is with the O atoms, specifically, so here we're just showing the oxygens)


Essentially, in the orange circles we have little oxygen elephants pulling on an imaginary tree at the origin. The problem is, the other two edges are missing little oxygen elephants-- so the tree is going down! Oh noes! 
If we look back at the uncentered structure, which has both Si and O atoms (they're just both in the same color [we also have these "X" atoms at the center of each "ball," but don't worry about that]), we see that we have elephant oxygens along all four edges (as well as two sets along each axis)-- but once we center it, we lose two edges of elephant oxygens, and the tree comes crashing down. Clearly something is amiss.

This means it is time to understand the behavior of the centering function!

Initially, I started trying to think in 2D, and this led to my being very confused about what was happening, such that I didn’t get the point of how things worked. Bad idea.
Lesson learned: when trying to understand something, it’s not stupid or simple-minded to start off with the simple model. Au contraire! Keeping things basic allows you to see and understand the important behavior, which will help you out when the system becomes more complicated. At any rate, it’s what scientists seem to believe, and it was wisdom that served me well.

So, let’s focus on 1D.

First, the function:
 xnew = xold – ROUND(xold/L)*L    (where L is the length of the unit cell)

So let’s pretend we’re looking at a unit cell (in this case, let’s just look at a line segment) of length 8, and let’s see what happens at each “quarter point” – so what happens to 0, 2, 4, 6, and 8.
 


For 0:                          
  xnew = 0 – ROUND(0/8)*8
        = 0 – ROUND(0)*8
        = 0 – 0*8
        = 0

For 4:
  xnew = 4 – ROUND(4/8)*8
        = 4 – ROUND(0.5)*8
        = 4 – 1*8
        = -4

For 8:
 xnew = 8 – ROUND(8/8)*8 = 0

For 2:
 xnew = 2 – ROUND(2/8)*8 = 2
For 6:
 xnew = 6 – ROUND(6/8)*8 = -2

To illustrate what happens, we can look at the original line, and see where the original points end up in the centered line:
                
             Original line:

               
             




Transformed line:
The color coding is intended
 to "trace" points.







Now, I will point out the interesting things. The points from 0 to right up to 4 (or more generally, from 0 to right up to L/2) end up being unchanged. The points from 4 to 8 (or L/2 to L) end up becoming the negative half of the line (well, plus 0), with L/2 becoming –L/2. It’s like we have cut the original line at the halfway point and moved what used to be the upper half to the end, so that the last point (L, or 8 in thi case) matches up with zero.  

The problem is, that now we have two points that get transformed to zero, and we have no point mapped onto 4, or L/2.

To look at more pretty pictures of projections of LTA….

Below, I noted how the transformation works. The blue is the original input structure, and the beige is the “centered” structure. Because the unit cell has so many nice lines of symmetry, I considered what happened to each of the four “balls” that make up the unit cell. If you don't get what's going on, don't worry about it, and just admire the pretty picture (at least, I think it's pretty). Or use the discussion about our 1D model to try to make sense of it! :]

     
Once again, I used color coding to trace things.
The arrows are intended to provide  perspective.





















And here we see that the “missing points” in the projection are located at Lx/2 and Ly/2, which is to be expected from our discussion.


 

In other words... it's like instead of having a set of elephants along each edge, as well as along the axes, we now have relocated the elephants which should be along the edges corresponding to the midpoints (Lx/2, and Ly/2) to the x and y axes (respectively). This means we have two sets of oxygen elephants located along the axes... stacked on top of each other, so to speak. This image, quite properly, is rather ridiculous.

Now I’ll fast forward the story, because I’ve probably already long lost my few readers.
(As always, feel free to ask me about anything I've mentioned. I'd LOVE to talk about it!)

Basically, we have the points at both 0 and L mapping on to the new zero point. So what I did was figure out which points in the centered structure which were located at zero (or rather, along an axis) originally came from a point whose x, y, or z value was equal to L, and then moved that point in the centered structure from 0 to L/2. [Well, actually, I moved it just a teeeeny bit to the left of L/2, because if you’ll remember, a point at L/2 gets moved to –L/2 (4 got moved to -4, in our 1D example above)].
To translate into elephant language, I looked at the silly stack of elephants on the axes and relocated the elephants on top to a more dignified position-- along the empty edges.

At the end of this process I had a centered, dipoleless structure (uh, in theory…). Moreover, because this structure is already centered, upon going through the centering function, nothing changes.

Here is the result of centering my new centered input structure (also, just so you know, the projections onto the yz and xz planes look the same):

                         

Yay! Things appear to be fixed!

BUT WAIT. The problem was the dipole, and now I needed to actually calculate the dipole and make sure it was zero. I’ll spare you the detail, but… THE STRUCTURE STILL HAD  A DIPOLE! Granted, it was a much smaller dipole than it originally had… but still! Not cool, man!

Unfortunately, this realization happened at nearly the end of my last day of research, and there was no real time to do more problem-solving.

What I can say is the following. If you will recall, all these pretty pictures are projections onto a plane—aka, squished donuts. I would argue that squished donuts are not as enjoyable as real donuts, and it is much the same with these projections. You lose information in the flattening process.

To get an idea of this, imagine that cube again. Now imagine giving the side edges of the cube a jagged cut, so when you look at it straight ahead, you see something like:
  

                                                             








The problem is, if you squish it toward the ground, you still just see:









This isn’t the best example, but the point is, we can imagine that there was important information being lost in the squishing process, such that while the projection was nicely symmetric (and thus dipole-less), the 3D structure still had rowdy elephants causing problems and knocking over trees.

Unfortunately, my story ends here. I have a bit more detailed information about the remaining problem (ask if interested), but alas, at this point my research time was over, and I needed to get ready to get on a plane to visit a certain Russian-enthusiast close to my heart (if very far away in spacetime). So I still don’t understand exactly what was happening in the 3D structure that I wasn’t seeing in the projections, and I don’t understand at all how that problem came about.

I did learn a few things, though, including:

1) I love staring at pictures of pretty crystals. !
2) Start small when trying to understand tricky things.
3) It’s okay to feel clueless and lost and not good enough. You are good enough. Just take a  deep breath, and start grasping onto whatever you can. Eventually things will start to make   sense.
4) It is good to start small, but don’t be surprised (or traumatized) when you take it up a level, and suddenly things are broken again. You’ve made progress! And you’re that much better at fixing things.

I learned this while getting lost in lines of Fortran and suspecting I was actually stupid and incompetent and while fearing that I would never understand what the hell was going on with these zeolite things…

But I suspect that what I learned this summer will extend far beyond the abstract world of atomistic simulations and impact the way I carry myself in everyday life--  in the same surprising way that playing around with code can extend beyond the virtual world and uncover some truth about reality.

Huzzah for computational chemistry! :D

Tuesday, June 12, 2012

Hailing the Summer

Greetings, fair Reader!

The summer adventures have begun.

 After a brief, happy sojourn home, I find myself back at school for exciting chemistry research adventures. I have finally more or less settled back into my room, with a new roommate and a new set of challenges to conquer. Exciting!

My research adventures started yesterday, and it rapidly became evident that I definitely have my work cut out for me in the next ten weeks...
I have already gotten a tiny bit deeper into Unix, discovered and explored Emacs, and am expected to gain working knowledge of Fortran by the end of the week, since that is the programming language I shall be working in. So in the last two days I have gone through about 160 pages of Fortran.... only 200ish to go! Woo!
Oh, and let's not forget the 100+ pages of reading that I copied for myself today....
It seems quite daunting, but I am rather excited, to be honest. A lot of work means a lot of learning... and I feel like the amount of learning I will be doing will be slightly ridiculous. In a good way.

But I do love that my nerdiness is increasing significantly. I think I may have to start gaming. Or go crazy and convert to Linux. Somehow or another I need to affirm my transition into this particular realm of nerdom.
In my mind, female computer sciencey nerds have a nice edge of badassery, and while skipping through my Fortran book, I like to think to myself- yeah... yeah, I could do that. I could be a cool nerd-girl. I could totally do that!
...But then I realize that my carefully penned notes, general tidiness and prim&proper-ness do seem to disqualify me from playing the role of badass nerd girl.
But hey, that doesn't have to stop me from feeling super cool about coding, does it?

I don't know why I am so enchanted by coding. Maybe because I have been woefully ignorant of how it all works. Computers and programming seem to be shrouded in some sort of magical veil. In some way, computers seem to grasp at the magic of life- quite literally.
Computers stand at the border between physical reality and the wonderful world of abstraction. They translate between the "real" world and the world of ideas. They partake in the mystery of Meaning.
Magic, I say!

I have set about reading I Am a Strange Loop, by Douglas Hofstadter. He is, quite simply, fantastic. The knowledge that he is at Indiana University seriously tempts me to delve into Cognitive Science and ambitiously strive to end up in his lab, because it could only be absolutely awesome. But I digress.
The book builds upon ideas Hofstadter introduced in Godel, Escher, Bach (GEB), but focuses on the concept of I, or the self. Consciousness. That slippery thing!

To my extreme delight, I Am a Strange Loop has succeeded in weaving together essential philosophical questions with cognitive science, basic neuroscience, logic/mathematics, and computer science. (It's amazing how he manages to meld together so many topics and questions I delight in!)
He plays with questions like: What does it mean to be alive? What does it mean to be me?  What does it mean to know? What is consciousness? How might consciousness arise? How can something have meaning?

I think that, through GEB, Hofstadter really got me to appreciate the idea that structure is the key to meaning. Structure... ah, how magical!
I do not think I am yet ready to write out my thoughts on the subject... my thoughts are still hazy and unorganized, but the picture is slowly starting to come together. I just have unstructured words to throw at you.
Words like logic, and structure, and thinking, and meaning, and language, and binary, and beauty.
Wonderful, magical words!

But I should stop my incoherent rambling on Hofstadter's books for the time being.

The days seem to be virtually endless. There is an amazing fifteen-and-a-half hours between sunrise and sunset!
By 7am it is bright and sunny, and the world beckons me to be out of bed.
Thankfully, I obliged the world today. I went for a walk-jog in the arb, and it was a wonderful, wonderful decision. The morning light was gold-like and happy, the plant-life was gorgeous, and a little creek which I found along my path convinced me that I was part of an enchanted world. It was absolutely lovely.

I am not sure what exactly I want to achieve during these bright summer days, but I know that I want to partake in a curious mixture of gentle loveliness and nerd-girl awesomeness. I want to go for daily walk-runs, I want to improve my flexibility, I want to attempt a plunge into the world of music by making an acquaintance with the piano.... I think mostly I want to realize that I really do have a certain degree of control over my life. It is the sort of truth that lurks dangerously in the background. Dangerously, because it is so obvious it seems to evade belief.

I have spent a lot of time feeling small and incapable and boring... and done nothing about it.
But, ha! That is not how the game is played, World! Nice try, but I've finally caught on to your trickery.
The game is played by soaking in programming languages. By having the courage to try to learn piano. By having the discipline to wake up in the morning and greet a beautiful day. The game is played by realizing that you want to do something worthwhile... and then taking a step in that direction.
It's so terrifying, but so wonderful and liberating!

I may get lost in the arb, or fail miserably at piano, or cook the worst meals ever produced on the face of the earth, or feel utterly lost in the world of chemistry. The chances are pretty high that all of these things will happen within the next few weeks. But I have a suspicion that with a bit of time and a lot of work, it's going to be okay.

Maybe there's still hope for badassery. Hmm. Can I be both lovely and badass?
Well... I do love a good paradox.