Hello Alex, As far I understand, the code as written should work. It could be that we don't wrap the GridData object correctly.
- Noel On 25 January 2010 08:40, Demiurg HG <[email protected]> wrote: > Hello Noel, > > I've reviewed this article > http://openbabel.org/wiki/OBDotNet#Handling_OBGenericData > As I understand I have to use .Downcast<> method. Unfortunetly it does not > help :( > > Now my code looks like this: > > elem_table = new OBElementTable(); > conv = new OBConversion(); > mol = new OBMol(); > > if (!conv.SetInFormat("CUBE")) { throw new Exception("cann`t set input > format");} > if (!conv.ReadFile(mol, "test3.cube")) { throw new Exception("cann`t open > \"test.cube\" file"); } > > mol.FindRingAtomsAndBonds(); > mol.Center(); > > VectorpData data_set = mol.GetAllData(openbabelcsharp.GridData); > > for (int i=0; i<data_set.Count; i++) { > OBGenericData data = data_set[i]; > OBGridData grid = data.Downcast<OBGridData>(); // <-- exception > } > > An unhandled exception of type 'System.InvalidCastException' occurred in > OBDotNet.dll > Additional information: No explicit downcast is defined for GridData. > > Thanks before hand. > Alex. > > 2010/1/22 Noel O'Boyle <[email protected]> >> >> Hello Alex, >> >> See the OBDotNet documentation for information on casting OB data >> types. BTW, questions about development with OB are better sent to the >> openbabel-scripting list. >> >> Hope this helps.... >> >> - Noel >> >> 2010/1/22 Demiurg HG <[email protected]>: >> > Hello, >> > >> > I`m trying to retrive charge density (OBGridData) from Gaussuan Cube >> > using >> > OBDotNet (latest version). >> > My code looks like this: >> > >> > conv = new OBConversion(); >> > mol = new OBMol(); >> > >> > if (!conv.SetInFormat("CUBE")) { >> > throw new Exception("cann`t set input format"); >> > } >> > >> > if (!conv.ReadFile(mol, "test3.cube")) { >> > throw new Exception("cann`t open \"test3.cube\" file"); >> > } >> > >> > VectorpData data_set = mol.GetAllData(openbabelcsharp.GridData); >> > >> > for (int i=0; i<data_set.Count; i++) { >> > OBGenericData data = data_set[i]; >> > Debug.WriteLine("Data #" + i + " : " + data.GetAttribute() + ", >> > type="+data.GetDataType() + data.ToString()); >> > >> > OBGridData grid = (OBGridData)data; // <-- InvalidCastException >> > } >> > >> > Molecule is loaded successfully. >> > data.GetDataType() returns 24 (openbabelcsharp.GridData) >> > An exception on type casting is occurs. >> > >> > What is a right way get OBGridData? >> > >> > Thanks before hand. >> > Alex. >> > > > ------------------------------------------------------------------------------ Throughout its 18-year history, RSA Conference consistently attracts the world's best and brightest in the field, creating opportunities for Conference attendees to learn about information security's most important issues through interactions with peers, luminaries and emerging and established companies. http://p.sf.net/sfu/rsaconf-dev2dev _______________________________________________ OpenBabel-scripting mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openbabel-scripting
