Skip to content

Commit c49246f

Browse files
committed
Fixed missing ensureHelperArray after parsing sketch
1 parent 1fdbaa9 commit c49246f

File tree

1 file changed

+12
-248
lines changed

1 file changed

+12
-248
lines changed

src/main/java/com/actelion/research/util/Sketch.java

100644100755
Lines changed: 12 additions & 248 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ public class Sketch
159159
private static final int MOLSIZE = 1440;
160160
private static final int REACTIONSIZE = 4000;
161161
private static final int PLUSSIZE = 20;
162-
163-
162+
163+
164164
// public static final int TAGNAMELEN (sizeof("MDLSK")/sizeof(char)+1);
165165
public static boolean createMolFromSketchFile(StereoMolecule mol, String szFileName)
166166
throws IOException
@@ -248,252 +248,16 @@ public static boolean writeReactionSketchFile(Reaction rxn, OutputStream os)
248248
{
249249
boolean ok = false;
250250
byte[] buffer = createSketchFromReaction(rxn);
251-
251+
252252
if (buffer != null) {
253253
os.write(buffer);
254254
ok = true;
255255
}
256-
256+
257257
return ok;
258258
}
259259

260-
261-
/*
262-
private int getMolObjectsOl(StereoMolecule mol,LittleEndianDataInputStream fp,int molAtoms[]) throws IOException
263-
{
264-
byte buff[] = new byte[1024];
265-
byte c;
266-
byte bval;
267-
short at1,at2,AtomType=0;
268-
int i;
269-
short t,val = 0,num=0;
270-
DblPoint dblCoords = new DblPoint();
271-
int ObjectCount=0;
272-
int MolObject=-1,BondObject=-1,AtomObject=-1;
273-
String s;
274-
275-
do {
276-
c = fp.readByte();
277-
278-
switch (c) {
279-
case $Version:
280-
ObjectCount=0;
281-
MolObject = -1;
282-
t = fp.readShort();
283-
bval = fp.readByte();
284-
break;
285-
286-
case $Totobjs:
287-
t = fp.readShort();
288-
val = fp.readShort();
289-
ObjectCount = -1; AtomObject=-1;BondObject=-1;
290-
break;
291-
292-
case $Obj:
293-
t = fp.readShort();
294-
bval = fp.readByte();
295-
switch(bval) {
296-
case $Obj_Mol:
297-
MolObject++;AtomObject=-1;BondObject=-1;
298-
AtomType = 0;
299-
ObjectCount = -1;
300-
break;
301-
case $Obj_Chiral:
302-
// mol.SetChiral(true);
303-
mol.setChiral(true);
304-
ObjectCount++;
305-
break;
306-
case $Obj_Bond:
307-
BondObject++;
308-
//System.out.println("mol.vectBonds.insert(mol.vectBonds.end(),bond);");
309-
// mol.vectBonds.insert(mol.vectBonds.end(),bond);
310-
ObjectCount++;
311-
AtomType = 0;
312-
break;
313-
case $Obj_Atom:
314-
AtomObject++;
315-
//CXR ChemDraw Problem C atoms are not defined with symbol and number!
316-
// strcpy(atom.Symbol,"C");
317-
// atom.Number = 6;
318-
// mol.vectAtoms.insert(mol.vectAtoms.end(),atom);
319-
mol.addAtom("C");
320-
ObjectCount++;
321-
AtomType = 0;
322-
break;
323-
324-
default:
325-
326-
ObjectCount++;
327-
break;
328-
}
329-
if (MolObject > 1) {
330-
System.err.println("Sorry Only One Molecule supported\n");
331-
return 1;
332-
}
333-
break;
334-
335-
case $Begsketch: // $BeginSketch
336-
t = fp.readShort();
337-
fp.readFully(buff,0,(int)t-2);
338-
// fp.BufRead(buff,t-2);
339-
break;
340-
341-
case $Endsketch: //$EndSketch
342-
t = fp.readShort();
343-
// return 0;
344-
break;
345-
case $Atom_coords: //$Atom_coords
346-
t = fp.readShort();
347-
dblCoords.x = fp.readFloat();
348-
dblCoords.y = fp.readFloat();
349-
// fp.BufRead(&dblCoords,sizeof(dblCoords));
350-
mol.setAtomX(AtomObject,dblCoords.x);
351-
// mol.vectAtoms[AtomObject].x = dblCoords.x;
352-
mol.setAtomY(AtomObject,dblCoords.y);
353-
// mol.vectAtoms[AtomObject].y = dblCoords.y;
354-
mol.setAtomZ(AtomObject,0);
355-
// mol.vectAtoms[AtomObject].z = 0;
356-
molAtoms[AtomObject] = ObjectCount;
357-
358-
// mol.vectAtoms[AtomObject].Number = ObjectCount;
359-
// mol.vectAtoms[AtomObject].Charge = 0;
360-
break;
361-
362-
case $Atom_type: //$Atom Type
363-
t = fp.readShort();
364-
AtomType = fp.readShort();
365-
// fp.BufRead(&AtomType,2);
366-
break;
367-
368-
case $Atom_symbol:
369-
t = fp.readShort();
370-
fp.readFully(buff,0,t-2);
371-
// fp.BufRead(buff,t-2);
372-
s = P2CStr(buff);
373-
System.out.println("Atom Symbol Length " + t + " sym = " + P2CStr(buff));
374-
// %d Sym=[%s]\n",t,(char *)P2CStr(buff));
375-
switch (AtomType) {
376-
case 270:
377-
System.out.println("Atom list");
378-
// strcpy(mol.vectAtoms[AtomObject].Symbol,"L");
379-
break;
380-
case 271:
381-
System.out.println("Atom not list");
382-
// mol.vectAtoms[AtomObject].bNotList = TRUE;
383-
// strcpy(mol.vectAtoms[AtomObject].Symbol,"L");
384-
break;
385-
default:
386-
System.out.println("Atom Symbol ");
387-
mol.setAtomicNo(AtomObject,Molecule.getAtomicNoFromLabel(s));
388-
// strcpy(mol.vectAtoms[AtomObject].Symbol,P2CStr(buff));
389-
break;
390-
}
391-
break;
392-
393-
case $Atom_list: //$Atom_List
394-
t = fp.readShort();
395-
num = fp.readShort();
396-
// fp.BufRead(&num,1); // read number of atoms in list
397-
for (i = 0; i < num ; i++) {
398-
val = fp.readShort(); // read atoms in list
399-
// mol.vectAtoms[AtomObject].List[i] = (int)val;
400-
//TRACE("Atom %d in List\n",(int)val);
401-
}
402-
// mol.vectAtoms[AtomObject].List[i] = -1;
403-
break;
404-
405-
case $Atom_alias: //$Atom Alias
406-
t = fp.readShort();
407-
fp.readFully(buff,0,t-2);
408-
// fp.BufRead(buff,t-2);
409-
break;
410-
411-
case $Atom_number: //Atom_number
412-
t = fp.readShort();
413-
val = fp.readShort();
414-
break;
415-
416-
case $Atom_chg: //$Atom_Charge
417-
t = fp.readShort();
418-
bval = fp.readByte();
419-
mol.setAtomCharge(AtomObject,((int)bval)-16);
420-
// System.out.println(" mol.vectAtoms[AtomObject].Charge = ((int)bval)-16;");
421-
// mol.vectAtoms[AtomObject].Charge = ((int)bval)-16;
422-
break;
423-
424-
case $Atom_rad: //Atom_rad
425-
t = fp.readShort();
426-
bval = fp.readByte();
427-
//TRACE("Atom Radical %d \n",bval);
428-
break;
429-
430-
case $Atom_msdif: //$Atom_msdif
431-
t = fp.readShort();
432-
bval = fp.readByte();
433-
//TRACE("Atom Mass Diff %d \n",bval);
434-
break;
435-
436-
case $Atom_valence: //$Atom_valence
437-
t = fp.readShort();
438-
bval = fp.readByte();
439-
//TRACE("Atom Valence %d \n",bval);
440-
break;
441-
442-
443-
case $Bond_atoms: //$Bond_atoms
444-
t = fp.readShort();
445-
at1 = fp.readShort();
446-
at2 = fp.readShort();
447-
mol.addBond(at1,at2,0);
448-
// fp.BufRead(&at1,2);
449-
// fp.BufRead(&at2,2);
450-
// System.out.println(" mol.vectBonds[BondObject].Atoms[0] = at1;");
451-
// mol.vectBonds[BondObject].Atoms[0] = at1;
452-
// mol.vectBonds[BondObject].Atoms[1] = at2;
453-
// mol.vectBonds[BondObject].Type = 1; // Default
454-
break;
455-
456-
case $Bond_type: //$Bond_type
457-
t = fp.readShort();
458-
bval = fp.readByte();
459-
setBondFeatures(mol,BondObject,(int)bval,0,0);
460-
// mol.setBondType(BondObject,getBondType((int)bval));
461-
// System.out.println("mol.vectBonds[BondObject].Type = (int)bval;");
462-
// mol.vectBonds[BondObject].Type = (int)bval;
463-
break;
464-
465-
case $Bond_stereo_type: //Bond_stereo_type
466-
t = fp.readShort();
467-
bval = fp.readByte();
468-
setBondFeatures(mol,BondObject,0,(int)bval,0);
469-
// System.out.println(" mol.vectBonds[BondObject].Stereo = (int)bval;");
470-
// mol.vectBonds[BondObject].Stereo = (int)bval;
471-
break;
472-
473-
474-
case $Atom_aamap_num: // Atom_aamap_num
475-
t = fp.readShort();
476-
val = fp.readShort();
477-
// System.out.println("mol.vectAtoms[AtomObject].AtomMap = (int)val;");
478-
mol.setAtomMapNo(AtomObject,(int)val,false);
479-
// mol.vectAtoms[AtomObject].AtomMap = (int)val;
480-
break;
481-
482-
case -1:
483-
break;
484-
485-
default:
486-
t = fp.readShort();
487-
fp.readFully(buff,0,t-2);
488-
// fp.BufRead(buff,t-2);
489-
break;
490260

491-
}
492-
} while (c != -1);
493-
CorrectBondAtomNumbering(mol,AtomObject+1, BondObject+1,molAtoms);
494-
return 1;
495-
}
496-
*/
497261
private static boolean getMolObjects(StereoMolecule molMain, LittleEndianDataInputStream fp)
498262
throws IOException
499263
{
@@ -601,7 +365,7 @@ private static boolean getMolObjects(StereoMolecule molMain, LittleEndianDataInp
601365

602366
if (!chiralFound)
603367
molMain.setToRacemate();
604-
368+
molMain.ensureHelperArrays(Molecule.cHelperAll);
605369
return ok;
606370
}
607371

@@ -696,7 +460,7 @@ private static Rect getBoundingRect(Molecule m)
696460
r.right = (short)Math.max(x, r.right);
697461
r.bottom = (short)Math.max(y, r.bottom);
698462
}
699-
debug("Bounding Rect for Molecule " + m + " is " + r.left + ","
463+
debug("Bounding Rect for Molecule " + m + " is " + r.left + ","
700464
+ r.top + "," + r.right + "," + r.bottom);
701465
return r;
702466
}
@@ -718,7 +482,7 @@ private static Rect2D getBoundingRectangle(Molecule m)
718482
r.bottom = Math.max(y, r.bottom);
719483
}
720484

721-
debug("Bounding Rect2D for Molecule " + m + " is " + r.left + ","
485+
debug("Bounding Rect2D for Molecule " + m + " is " + r.left + ","
722486
+ r.top + "," + r.right + "," + r.bottom);
723487
return r;
724488
}
@@ -738,7 +502,7 @@ private static Rect2D getBoundingRectangle(Reaction rxn)
738502
r.bottom = Math.max(r.bottom, rm.bottom);
739503
}
740504

741-
debug("Bounding Rect2D for Reaction " + rxn + " is " + r.left + ","
505+
debug("Bounding Rect2D for Reaction " + rxn + " is " + r.left + ","
742506
+ r.top + "," + r.right + "," + r.bottom);
743507
return r;
744508
}
@@ -852,7 +616,7 @@ private static boolean getMolObject(StereoMolecule mol, LittleEndianDataInputStr
852616

853617
if (!chiralFound)
854618
mol.setToRacemate();
855-
619+
856620
return true;
857621

858622
case $Atom_coords: //$Atom_coords
@@ -1728,7 +1492,7 @@ public static byte[] createSketchFromReaction(Reaction r)
17281492
if (i < (reactants - 1)) {
17291493
Rect rn = getBoundingRect(rxn.getMolecule(i + 1));
17301494
Rect rp = calcMiddleRect(rc, rn, PLUSSIZE);
1731-
debug("Writing plus at " +
1495+
debug("Writing plus at " +
17321496
rp.left + "," + rp.top + "," + rp.right + "," + rp.bottom);
17331497
writePlus(fp, rp, -1, -1);
17341498
}
@@ -2201,8 +1965,8 @@ static int getMDLBondType(int btype, boolean bstereo)
22011965
return order;
22021966
}
22031967
}
2204-
2205-
1968+
1969+
22061970
private static void debug(String s)
22071971
{
22081972
if (debug_)

0 commit comments

Comments
 (0)