Skip to content

Commit 6cc2697

Browse files
authored
#3604 Add api methods to interact with atoms and bonds in s-groups (#3625)
1 parent 8821aa2 commit 6cc2697

62 files changed

Lines changed: 1922 additions & 798 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/c/indigo/indigo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,12 @@ CEXPORT int indigoGetSGroupNumCrossBonds(int sgroup);
614614
CEXPORT int indigoCreateCrossBonds(int sgroup);
615615
CEXPORT int indigoClearSGroupCrossBonds(int sgroup);
616616

617+
// Issue #3604: New SGroup API methods
618+
CEXPORT int indigoAddSGroup(int molecule, const char* type, int extindex);
619+
CEXPORT int indigoSetSGroupAtoms(int sgroup, int natoms, int* atoms);
620+
CEXPORT int indigoSetSGroupBonds(int sgroup, int nbonds, int* bonds);
621+
CEXPORT int indigoIterateSGroupCrossBonds(int sgroup);
622+
617623
CEXPORT int indigoAddSGroupAttachmentPoint(int sgroup, int aidx, int lvidx, const char* apid);
618624
CEXPORT int indigoDeleteSGroupAttachmentPoint(int sgroup, int index);
619625
// Returns iterator of superatom attachment points (SAP entries) for a superatom S-group.

api/c/indigo/src/indigo_abbreviations_expand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ namespace indigo
762762

763763
int sid = mol.sgroups.addSGroup(SGroup::SG_TYPE_SUP);
764764
Superatom& super = (Superatom&)mol.sgroups.getSGroup(sid);
765-
super.subscript.readString(mol.getPseudoAtom(v), true);
765+
super.label.readString(mol.getPseudoAtom(v), true);
766766
for (int ve = expanded.vertexBegin(); ve != expanded.vertexEnd(); ve = expanded.vertexNext(ve))
767767
super.atoms.push(mapping[ve]);
768768

api/c/indigo/src/indigo_molecule.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ IndigoObject* IndigoSGroupAtomsIter::next()
11881188
return new IndigoAtom(_mol, _sgroup.atoms[_idx]);
11891189
}
11901190

1191-
IndigoSGroupBondsIter::IndigoSGroupBondsIter(BaseMolecule& mol, SGroup& sgroup) : IndigoObject(SGROUP_ATOMS_ITER), _mol(mol), _sgroup(sgroup)
1191+
IndigoSGroupBondsIter::IndigoSGroupBondsIter(BaseMolecule& mol, SGroup& sgroup) : IndigoObject(SGROUP_BONDS_ITER), _mol(mol), _sgroup(sgroup)
11921192
{
11931193
_idx = -1;
11941194
}
@@ -1199,7 +1199,7 @@ IndigoSGroupBondsIter::~IndigoSGroupBondsIter()
11991199

12001200
bool IndigoSGroupBondsIter::hasNext()
12011201
{
1202-
return _idx + 1 < _sgroup.bonds.size();
1202+
return _idx + 1 < _sgroup.getBonds().size();
12031203
}
12041204

12051205
IndigoObject* IndigoSGroupBondsIter::next()
@@ -1208,7 +1208,30 @@ IndigoObject* IndigoSGroupBondsIter::next()
12081208
return 0;
12091209

12101210
_idx++;
1211-
return new IndigoBond(_mol, _sgroup.bonds[_idx]);
1211+
return new IndigoBond(_mol, _sgroup.getBonds()[_idx]);
1212+
}
1213+
1214+
IndigoSGroupXBondsIter::IndigoSGroupXBondsIter(BaseMolecule& mol, SGroup& sgroup) : IndigoObject(SGROUP_BONDS_ITER), _mol(mol), _sgroup(sgroup)
1215+
{
1216+
_idx = -1;
1217+
}
1218+
1219+
IndigoSGroupXBondsIter::~IndigoSGroupXBondsIter()
1220+
{
1221+
}
1222+
1223+
bool IndigoSGroupXBondsIter::hasNext()
1224+
{
1225+
return _idx + 1 < _sgroup.xbonds.size();
1226+
}
1227+
1228+
IndigoObject* IndigoSGroupXBondsIter::next()
1229+
{
1230+
if (!hasNext())
1231+
return 0;
1232+
1233+
_idx++;
1234+
return new IndigoBond(_mol, _sgroup.xbonds[_idx]);
12121235
}
12131236

12141237
int _indigoIterateAtoms(Indigo& self, int molecule, int type)
@@ -1352,7 +1375,7 @@ CEXPORT int indigoCountBonds(int molecule)
13521375

13531376
auto sg = _getSGroupFromObject(obj);
13541377
if (sg)
1355-
return sg.get().bonds.size();
1378+
return sg.get().getBonds().size();
13561379

13571380
BaseMolecule& mol = obj.getBaseMolecule();
13581381

api/c/indigo/src/indigo_molecule.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,22 @@ class IndigoSGroupBondsIter : public IndigoObject
559559
int _idx;
560560
};
561561

562+
// Iterates xbonds (crossing bonds) directly, not polymorphic getBonds()
563+
class IndigoSGroupXBondsIter : public IndigoObject
564+
{
565+
public:
566+
IndigoSGroupXBondsIter(BaseMolecule& mol, SGroup& sgroup);
567+
~IndigoSGroupXBondsIter() override;
568+
569+
IndigoObject* next() override;
570+
bool hasNext() override;
571+
572+
protected:
573+
BaseMolecule& _mol;
574+
SGroup& _sgroup;
575+
int _idx;
576+
};
577+
562578
class IndigoMoleculeComponent : public IndigoObject
563579
{
564580
public:

0 commit comments

Comments
 (0)