http://qs321.pair.com?node_id=349692

freak has asked for the wisdom of the Perl Monks concerning the following question:

when i define 2 molecules like:

use Chemistry::Mol; $mol = Chemistry::Mol->new(id => "mol_id", name => "my molecule"); $c = $mol->new_atom(symbol => "C", coords => [0,0,0]); $o = $mol->new_atom(symbol => "O", coords => [0,0,1.23]); $mol->new_bond(atoms => [$c, $o], order => 3);

How can i combine them into one molecula ? like : $z = $c + $o; ?

print $mol->print;

20040501 Edit by Corion: Moved it to SoPW and added formatting

Replies are listed 'Best First'.
Re: Combining two molecules with the perl chemistry modules
by Corion (Patriarch) on May 01, 2004 at 21:30 UTC

    Hello and welcome, freak
    as you propably have noticed, I have edited a good lot of your posts, moved them to Seekers of Perl Wisdom and added formatting so they look pleasing to the eye.

    I also did send you personal messages about this, and pointed you to the Writeup Formatting Tips and the Perlmonks Approved HTML Tags, in addition to Where do I post X, so you would learn for your next posts where they should go.

    You have, to this date, not replied to my messages nor have you shown any improvement in the placement and content of your root nodes - that's why I place a reply here that does not answer your immediate question.

    Please read all the above links, and possibly in addition read How (Not) To Ask A Question.

    Have fun,
    Corion

Re: Combining two molecules with the perl chemistry modules
by simonm (Vicar) on May 01, 2004 at 21:33 UTC
    How can i combine them into one molecula ?

    There doesn't seem to be a trivial way to do this.

    I think you may need to decide how you're going to bond the two molecules, then create a new molecule, looping over the atoms and bonds in the source molecules and adding them to the new one.

    I bet such a routine would be a useful addition to the Chemistry modules...

Re: Combining two molecules with the perl chemistry modules
by Anonymous Monk on May 03, 2004 at 23:39 UTC
    Hi, I'm ITUB, the author of Chemistry::Mol (I don't have an account here). These modules are still far from finished, so they still lack methods for joining and splitting molecules. Therefore the only general method of joining molecules is what simonm suggested.

    However, the code you give suggests that the question you were really asking was actually answered by Mr. Muskrat.

    Anyway, if you want more information on this project (still under construction, as I said), go to http://www.perlmol.org. You can subscribe to the mailing list if you want to hear about updates.

Re: Combining two molecules with the perl chemistry modules
by Mr. Muskrat (Canon) on May 03, 2004 at 05:18 UTC

    How can i combine them into one molecula ?

    You already did that with the new_bond.

    Update: $mol contains the CO molecule that you created.

Re: Combining two molecules with the perl chemistry modules
by CountZero (Bishop) on May 02, 2004 at 20:39 UTC
    I think that if you can find a general formula to calculate the combination of two different molecules, you will probably get the Nobel Prize for chemistry on the spot.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law