Ok, I was being lazy about all the Hashtables being thrown around.
Here is a more strongly-typed version:

http://gist.github.com/466912/c578bb2c41c0cd2906fe3556e973d4ba8785ed55

There were lots of casts of the type
((Double)map.get(key)).doubleValue(); that are unnecessary with java
1.6's generics and unboxing. However, be sure to test to make sure I
haven't caused some subtle Integer/Double casting error.

I'm guessing that the use of doubles everywhere is because reactions
can have fractional stoichiometries? Like 1.5*benzene + 2.3 HOH = ?

Well, anyway, hope it now works...

gilleain

On 7/7/10, wateriestfire <[email protected]> wrote:
>
> Hey,
>
> Thanks for replying, you have been very helpful, however Java gave me this
> error when I tried to run your modification:
>
> Exception in thread "main" java.lang.ClassCastException:
> org.openscience.cdk.Atom cannot be cast to java.lang.String
>       at ReactionBalancer.removeZeroEntries(ReactionBalancer.java:430)
>       at ReactionBalancer.makeDiffHashtable(ReactionBalancer.java:187)
>       at ReactionBalancer.balance(ReactionBalancer.java:140)
>       at Tester.main(Tester.java:81)
>
> on line 430, and at 263 specifically... I tried casting them as Objects and
> as Atoms, but then it only gave the answer "false" when I did it on known
> equations.
>
> thanks, I feel we are on the verge of solving this. :)
>
>
>
> gilleain torrance wrote:
>>
>> Hi,
>>
>> I know very little about the reaction code in the cdk, but I've made
>> some small changes to the ReactionBalancer class you posted:
>>
>> http://gist.github.com/466912
>>
>> which also now needs this class:
>>
>> http://gist.github.com/466913
>>
>> to replace the old cdk.math.PermutationGenerator class (there is an
>> AtomContainerPermutor class, but that isn't suitable for permuting a
>> Double[]).
>>
>> Now, it might be that the functionality of the ReactionBalancer has
>> been moved, but this should work ... although I only know that it
>> compiles, not that it works :)
>>
>> gilleain
>>
>> On Wed, Jul 7, 2010 at 3:24 PM, wateriestfire <[email protected]>
>> wrote:
>>>
>>> Here is the original source code for ReactionBalancer.java, it is
>>> incompatible with the newest version of the CDK, I don't know if it
>>> helps, I
>>> have tried converting it myself to work with the newest versions, but I
>>> haven't been able to get it right.
>>>
>>> Thanks again!
>>> http://old.nabble.com/file/p29096830/ReactionBalancer.java
>>> ReactionBalancer.java
>>>
>>>
>>> wateriestfire wrote:
>>>>
>>>> ReactionBalancer used to be a class in the CDK, and what it did was
>>>> check
>>>> to see if a reaction could be balanced, It was then removed... Now I
>>>> have
>>>> a list of reactions, and while I am parsing them, I need to know if they
>>>> can be balanced, or to actually balance them would be nice too.
>>>>
>>>> Is there a class in the CDK that can do this?
>>>>
>>>> Thanks,
>>>>
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Balancing-Chemical-Reactions--tp29095305p29096830.html
>>> Sent from the cdk-user mailing list archive at Nabble.com.
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> This SF.net email is sponsored by Sprint
>>> What will you do first with EVO, the first 4G phone?
>>> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
>>> _______________________________________________
>>> Cdk-user mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/cdk-user
>>>
>>
>> ------------------------------------------------------------------------------
>> This SF.net email is sponsored by Sprint
>> What will you do first with EVO, the first 4G phone?
>> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
>> _______________________________________________
>> Cdk-user mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/cdk-user
>>
>>
>
> --
> View this message in context:
> http://old.nabble.com/Balancing-Chemical-Reactions--tp29095305p29099865.html
> Sent from the cdk-user mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> _______________________________________________
> Cdk-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/cdk-user
>

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Cdk-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cdk-user

Reply via email to