1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**********************************************************************
smilesvalence.h - Implement SMILES valence model.
Copyright (C) 2016,2017 by Noel O'Boyle
This file is part of the Open Babel project.
For more information, see <http://openbabel.org/>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
***********************************************************************/
static bool IsOutsideOrganicSubset(unsigned int elem)
{
switch (elem) {
case 0: // *
case 5: // B
case 6: // C
case 7: // N
case 15: // P
case 8: // O
case 16: // S
case 9: // F
case 17: // Cl
case 35: // Br
case 53: // I
return false;
default:
return true;
}
}
/* Return the implicit Smiles valence for element "elem" with neutral charge
* and "val" explicit nbrs. When writing SMILES, a return value of 0 indicates a hypervalent structure
*/
static unsigned int SmilesValence(unsigned int elem, unsigned int val, bool reading=true)
{
switch (elem) {
case 5: // B
if (val <= 3) return 3;
break;
case 6: // C
if (val <= 4) return 4;
break;
case 7: // N
case 15: // P
switch (val) {
case 0:
case 1:
case 2:
case 3:
return 3;
case 4:
case 5:
return 5;
}
break;
case 8: // O
if (val <= 2) return 2;
break;
case 16: // S
switch (val) {
case 0:
case 1:
case 2:
return 2;
case 3:
case 4:
return 4;
case 5:
case 6:
return 6;
}
break;
case 9: // F
case 17: // Cl
case 35: // Br
case 53: // I
if (val <= 1) return 1;
break;
}
return reading ? val : 0;
}