Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/c/indigo/indigo.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,12 @@ CEXPORT int indigoGetSGroupNumCrossBonds(int sgroup);
CEXPORT int indigoCreateCrossBonds(int sgroup);
CEXPORT int indigoClearSGroupCrossBonds(int sgroup);

// Issue #3604: New SGroup API methods
CEXPORT int indigoAddSGroup(int molecule, const char* type, int extindex);
CEXPORT int indigoSetSGroupAtoms(int sgroup, int natoms, int* atoms);
CEXPORT int indigoSetSGroupBonds(int sgroup, int nbonds, int* bonds);
CEXPORT int indigoIterateSGroupCrossBonds(int sgroup);

CEXPORT int indigoAddSGroupAttachmentPoint(int sgroup, int aidx, int lvidx, const char* apid);
CEXPORT int indigoDeleteSGroupAttachmentPoint(int sgroup, int index);
// Returns iterator of superatom attachment points (SAP entries) for a superatom S-group.
Expand Down
2 changes: 1 addition & 1 deletion api/c/indigo/src/indigo_abbreviations_expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ namespace indigo

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

Expand Down
6 changes: 3 additions & 3 deletions api/c/indigo/src/indigo_molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ IndigoSGroupBondsIter::~IndigoSGroupBondsIter()

bool IndigoSGroupBondsIter::hasNext()
{
return _idx + 1 < _sgroup.bonds.size();
return _idx + 1 < _sgroup.getBonds().size();
}

IndigoObject* IndigoSGroupBondsIter::next()
Expand All @@ -1168,7 +1168,7 @@ IndigoObject* IndigoSGroupBondsIter::next()
return 0;

_idx++;
return new IndigoBond(_mol, _sgroup.bonds[_idx]);
return new IndigoBond(_mol, _sgroup.getBonds()[_idx]);
}

int _indigoIterateAtoms(Indigo& self, int molecule, int type)
Expand Down Expand Up @@ -1312,7 +1312,7 @@ CEXPORT int indigoCountBonds(int molecule)

auto sg = _getSGroupFromObject(obj);
if (sg)
return sg.get().bonds.size();
return sg.get().getBonds().size();

BaseMolecule& mol = obj.getBaseMolecule();

Expand Down
167 changes: 130 additions & 37 deletions api/c/indigo/src/indigo_molecule_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ void IndigoSuperatom::remove()

const char* IndigoSuperatom::getName()
{
return ((Superatom&)mol.sgroups.getSGroup(idx)).subscript.ptr();
return ((Superatom&)mol.sgroups.getSGroup(idx)).label.ptr();
}

IndigoSuperatom& IndigoSuperatom::cast(IndigoObject& obj)
Expand Down Expand Up @@ -1356,7 +1356,7 @@ CEXPORT int indigoAddDataSGroup(int molecule, int natoms, int* atoms, int nbonds
dsg.atoms.concat(atoms, natoms);

if (bonds != nullptr)
dsg.bonds.concat(bonds, nbonds);
dsg.cbonds.concat(bonds, nbonds);

if (data != nullptr)
dsg.data.readString(data, true);
Expand All @@ -1375,7 +1375,7 @@ CEXPORT int indigoAddSuperatom(int molecule, int natoms, int* atoms, const char*
BaseMolecule& mol = self.getObject(molecule).getBaseMolecule();
int idx = mol.sgroups.addSGroup(SGroup::SG_TYPE_SUP);
Superatom& satom = (Superatom&)mol.sgroups.getSGroup(idx);
satom.subscript.appendString(name, true);
satom.label.appendString(name, true);
if (atoms == nullptr)
throw IndigoError("indigoAddSuperatom(): atoms were not specified");

Expand All @@ -1393,8 +1393,8 @@ CEXPORT int indigoSetDataSGroupXY(int sgroup, float x, float y, const char* opti
{
DataSGroup& dsg = IndigoDataSGroup::cast(self.getObject(sgroup)).get();

dsg.display_pos.x = x;
dsg.display_pos.y = y;
dsg.display_pos->x = x;
dsg.display_pos->y = y;
dsg.detached = true;

if (options != 0 && options[0] != 0)
Expand Down Expand Up @@ -1432,8 +1432,8 @@ CEXPORT int indigoSetSGroupCoords(int sgroup, float x, float y)
{
DataSGroup& dsg = IndigoDataSGroup::cast(self.getObject(sgroup)).get();

dsg.display_pos.x = x;
dsg.display_pos.y = y;
dsg.display_pos->x = x;
dsg.display_pos->y = y;

return 1;
}
Expand Down Expand Up @@ -1592,7 +1592,7 @@ CEXPORT int indigoSetSGroupXCoord(int sgroup, float x)
{
DataSGroup& dsg = IndigoDataSGroup::cast(self.getObject(sgroup)).get();

dsg.display_pos.x = x;
dsg.display_pos->x = x;

return 1;
}
Expand All @@ -1605,7 +1605,7 @@ CEXPORT int indigoSetSGroupYCoord(int sgroup, float y)
{
DataSGroup& dsg = IndigoDataSGroup::cast(self.getObject(sgroup)).get();

dsg.display_pos.y = y;
dsg.display_pos->y = y;

return 1;
}
Expand Down Expand Up @@ -1637,11 +1637,11 @@ CEXPORT int indigoCreateSGroup(const char* type, int mapping, const char* name)
if (((sgroup.atoms.find(edge.beg) != -1) && (sgroup.atoms.find(edge.end) == -1)) ||
((sgroup.atoms.find(edge.end) != -1) && (sgroup.atoms.find(edge.beg) == -1)))
{
sgroup.bonds.push(i);
sgroup.xbonds.push(i);
}
}

sgroup.subscript.appendString(name, true);
sgroup.label.appendString(name, true);

if (sgroup.sgroup_type == SGroup::SG_TYPE_SUP)
{
Expand Down Expand Up @@ -1698,7 +1698,7 @@ CEXPORT int indigoSetSGroupName(int sgroup, const char* sgname)
{
IndigoObject& obj = self.getObject(sgroup);
SGroup& sg = IndigoSGroup::cast(obj).get();
sg.subscript.readString(sgname, true);
sg.label.readString(sgname, true);

return 1;
}
Expand All @@ -1711,9 +1711,9 @@ CEXPORT const char* indigoGetSGroupName(int sgroup)
{
IndigoObject& obj = self.getObject(sgroup);
SGroup& sg = IndigoSGroup::cast(obj).get();
if (sg.subscript.size() < 1)
if (sg.label.size() < 1)
return "";
return sg.subscript.ptr();
return sg.label.ptr();
}
INDIGO_END(0);
}
Expand All @@ -1722,52 +1722,145 @@ CEXPORT int indigoGetSGroupNumCrossBonds(int sgroup)
{
INDIGO_BEGIN
{
Superatom& sup = IndigoSuperatom::cast(self.getObject(sgroup)).get();
return sup.bonds.size();
IndigoSGroup& isg = IndigoSGroup::cast(self.getObject(sgroup));
return isg.get().xbonds.size();
}
INDIGO_END(-1);
}

static void _fillCrossBonds(BaseMolecule& mol, SGroup& sg)
{
sg.xbonds.clear();
for (auto atom_idx : sg.atoms)
{
const Vertex& vx = mol.getVertex(atom_idx);
for (auto nei_idx = vx.neiBegin(); nei_idx != vx.neiEnd(); nei_idx = vx.neiNext(nei_idx))
{
if (sg.atoms.find(vx.neiVertex(nei_idx)) == -1)
{
int edge_idx = vx.neiEdge(nei_idx);
if (sg.xbonds.find(edge_idx) == -1)
sg.xbonds.push(edge_idx);
}
}
}
}

CEXPORT int indigoCreateCrossBonds(int sgroup)
{
INDIGO_BEGIN
{
IndigoSuperatom& isup = IndigoSuperatom::cast(self.getObject(sgroup));
Superatom& sup = isup.get();
BaseMolecule& mol = isup.mol;
IndigoSGroup& isg = IndigoSGroup::cast(self.getObject(sgroup));
_fillCrossBonds(isg.mol, isg.get());
return 1;
}
INDIGO_END(-1);
}

sup.bonds.clear();
CEXPORT int indigoClearSGroupCrossBonds(int sgroup)
{
INDIGO_BEGIN
{
IndigoSGroup& isg = IndigoSGroup::cast(self.getObject(sgroup));
isg.get().xbonds.clear();
return 1;
}
INDIGO_END(-1);
}

for (auto atom_idx : sup.atoms)
static IndigoObject* _wrapSGroup(BaseMolecule& mol, int idx)
{
switch (mol.sgroups.getSGroup(idx).sgroup_type)
{
case SGroup::SG_TYPE_SUP:
return new IndigoSuperatom(mol, idx);
case SGroup::SG_TYPE_SRU:
return new IndigoRepeatingUnit(mol, idx);
case SGroup::SG_TYPE_MUL:
return new IndigoMultipleGroup(mol, idx);
case SGroup::SG_TYPE_DAT:
return new IndigoDataSGroup(mol, idx);
default:
return new IndigoGenericSGroup(mol, idx);
}
}

CEXPORT int indigoAddSGroup(int molecule, const char* type, int extindex)
{
INDIGO_BEGIN
{
BaseMolecule& mol = self.getObject(molecule).getBaseMolecule();
int idx = mol.sgroups.addSGroup(type);
if (idx == -1)
throw IndigoError("indigoAddSGroup: cannot add SGroup of type '%s'", type);

SGroup& sgroup = mol.sgroups.getSGroup(idx);
if (extindex > 0)
sgroup.original_group = extindex;

return self.addObject(_wrapSGroup(mol, idx));
}
INDIGO_END(-1);
}

CEXPORT int indigoSetSGroupAtoms(int sgroup, int natoms, int* atoms)
{
INDIGO_BEGIN
{
IndigoSGroup& isg = IndigoSGroup::cast(self.getObject(sgroup));
SGroup& s = isg.get();

s.atoms.clear();
if (atoms != nullptr && natoms > 0)
{
const Vertex& vx = mol.getVertex(atom_idx);
for (auto nei_idx = vx.neiBegin(); nei_idx != vx.neiEnd(); nei_idx = vx.neiNext(nei_idx))
for (int i = 0; i < natoms; i++)
{
if (sup.atoms.find(vx.neiVertex(nei_idx)) == -1)
{
int edge_idx = vx.neiEdge(nei_idx);
if (sup.bonds.find(edge_idx) == -1)
sup.bonds.push(edge_idx);
}
if (atoms[i] < 0 || atoms[i] >= isg.mol.vertexEnd())
throw IndigoError("indigoSetSGroupAtoms: atom index %d out of range", atoms[i]);
s.atoms.push(atoms[i]);
}
}

return 1;
}
INDIGO_END(-1);
}

CEXPORT int indigoClearSGroupCrossBonds(int sgroup)
CEXPORT int indigoSetSGroupBonds(int sgroup, int nbonds, int* bonds)
{
INDIGO_BEGIN
{
Superatom& sup = IndigoSuperatom::cast(self.getObject(sgroup)).get();
sup.bonds.clear();
IndigoSGroup& isg = IndigoSGroup::cast(self.getObject(sgroup));
SGroup& s = isg.get();

if (s.sgroup_type != SGroup::SG_TYPE_DAT)
throw IndigoError("indigoSetSGroupBonds: only DAT SGroups support explicit bond assignment");

DataSGroup& dsg = (DataSGroup&)s;
dsg.cbonds.clear();
if (bonds != nullptr && nbonds > 0)
{
for (int i = 0; i < nbonds; i++)
{
if (bonds[i] < 0 || bonds[i] >= isg.mol.edgeEnd())
throw IndigoError("indigoSetSGroupBonds: bond index %d out of range", bonds[i]);
dsg.cbonds.push(bonds[i]);
}
}
return 1;
}
INDIGO_END(-1);
}

CEXPORT int indigoIterateSGroupCrossBonds(int sgroup)
{
INDIGO_BEGIN
{
IndigoSGroup& isg = IndigoSGroup::cast(self.getObject(sgroup));
return self.addObject(new IndigoSGroupBondsIter(isg.mol, isg.get()));
}
INDIGO_END(-1);
}

CEXPORT int indigoAddSGroupAttachmentPoint(int sgroup, int aidx, int lvidx, const char* apid)
{
INDIGO_BEGIN
Expand Down Expand Up @@ -1918,7 +2011,7 @@ CEXPORT int indigoGetSGroupDisplayOption(int sgroup)
{
Superatom& sup = IndigoSuperatom::cast(self.getObject(sgroup)).get();
if (sup.contracted > DisplayOption::Undefined)
return (int)sup.contracted;
return (int)(sup.contracted.hasValue() ? sup.contracted.get() : DisplayOption::Undefined);

return 0;
}
Expand Down Expand Up @@ -1957,8 +2050,8 @@ CEXPORT float* indigoGetSGroupCoords(int sgroup)

auto& tmp = self.getThreadTmpData();
auto& xy = ds.get().display_pos;
tmp.xyz[0] = xy.x;
tmp.xyz[1] = xy.y;
tmp.xyz[0] = xy->x;
tmp.xyz[1] = xy->y;
tmp.xyz[2] = 0.f;
return tmp.xyz;
}
Expand All @@ -1980,7 +2073,7 @@ CEXPORT const char* indigoGetRepeatingUnitSubscript(int sgroup)
INDIGO_BEGIN
{
RepeatingUnit& ru = IndigoRepeatingUnit::cast(self.getObject(sgroup)).get();
return ru.subscript.ptr();
return ru.label.ptr();
}
INDIGO_END(0);
}
Expand Down
13 changes: 13 additions & 0 deletions api/dotnet/src/IndigoLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,19 @@ public unsafe class IndigoLib
[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoClearSGroupCrossBonds(int sgroup);

// Issue #3604: New SGroup API methods
[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoAddSGroup(int molecule, string type, int extindex);

[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoSetSGroupAtoms(int sgroup, int natoms, int[] atoms);

[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoSetSGroupBonds(int sgroup, int nbonds, int[] bonds);

[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoIterateSGroupCrossBonds(int sgroup);

[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoAddSGroupAttachmentPoint(int sgroup, int aidx, int lvidx, string apid);

Expand Down
Loading
Loading