in packages/ketcher-core/src/domain/serializers/smi/smiles.js [420:572]
Smiles.prototype.writeAtom = function (
mol,
idx,
aromatic,
lowercase,
chirality,
) {
// eslint-disable-line max-params, max-statements
const atom = mol.atoms.get(idx);
let needBrackets = false;
let hydro = -1;
let aam = 0;
/*
if (mol.haveQueryAtoms())
{
query_atom = &mol.getQueryAtom(idx);
if (query_atom->type == QUERY_ATOM_RGROUP)
{
if (mol.getRGroups()->isRGroupAtom(idx))
{
const Array<int> &rg = mol.getRGroups()->getSiteRGroups(idx);
if (rg.length != 1)
throw Error("rgroup count %d", rg.length);
_output.printf("[&%d]", rg[0] + 1);
}
else
_output.printf("[&%d]", 1);
return;
}
}
*/
if (atom.label === 'A') {
this.smiles += '*';
return;
}
if (atom.label === 'R' || atom.label === 'R#') {
this.smiles += '[*]';
return;
}
// KETCHER-598 (Ketcher does not save AAM into reaction SMILES)
// BEGIN
// if (this.atom_atom_mapping)
// aam = atom_atom_mapping[idx];
aam = atom.aam;
// END
if (
atom.label !== 'C' &&
atom.label !== 'P' &&
atom.label !== 'N' &&
atom.label !== 'S' &&
atom.label !== 'O' &&
atom.label !== 'Cl' &&
atom.label !== 'F' &&
atom.label !== 'Br' &&
atom.label !== 'B' &&
atom.label !== 'I'
) {
needBrackets = true;
}
if (
atom.explicitValence >= 0 ||
atom.radical !== 0 ||
chirality > 0 ||
(aromatic && atom.label !== 'C' && atom.label !== 'O') ||
(aromatic &&
atom.label === 'C' &&
this.atoms[idx].neighbours.length < 3 &&
this.atoms[idx].h_count === 0)
) {
hydro = this.atoms[idx].h_count;
}
let label = atom.label;
if (atom.atomList && !atom.atomList.notList) {
label = atom.atomList.label();
needBrackets = false; // atom list label already has brackets
} else if (atom.isPseudo() || (atom.atomList && atom.atomList.notList)) {
label = '*';
needBrackets = false;
} else if (
chirality ||
(atom.charge !== 0 && atom.charge !== null) ||
atom.isotope > 0 ||
hydro >= 0 ||
aam > 0
) {
needBrackets = true;
}
if (needBrackets) {
if (hydro === -1) hydro = this.atoms[idx].h_count;
this.smiles += '[';
}
if (atom.isotope > 0) this.smiles += atom.isotope;
if (lowercase) this.smiles += label.toLowerCase();
else this.smiles += label;
if (chirality > 0) {
if (chirality === 1) this.smiles += '@';
// chirality == 2
else this.smiles += '@@';
if (atom.implicitH > 1) {
throw new Error(atom.implicitH + ' implicit H near stereocenter');
}
}
if (atom.label !== 'H') {
if (hydro > 1 || (hydro === 0 && !needBrackets)) this.smiles += 'H' + hydro;
else if (hydro === 1) this.smiles += 'H';
}
if (atom.charge > 1) this.smiles += '+' + atom.charge;
else if (atom.charge < -1) this.smiles += atom.charge;
else if (atom.charge === 1) this.smiles += '+';
else if (atom.charge === -1) this.smiles += '-';
if (aam > 0) this.smiles += ':' + aam;
if (needBrackets) this.smiles += ']';
/*
if (mol.getRGroupFragment() != 0)
{
for (i = 0; i < 2; i++)
{
int j;
for (j = 0; mol.getRGroupFragment()->getAttachmentPoint(i, j) != -1; j++)
if (idx == mol.getRGroupFragment()->getAttachmentPoint(i, j))
{
_output.printf("([*])");
break;
}
if (mol.getRGroupFragment()->getAttachmentPoint(i, j) != -1)
break;
}
}
*/
};