Repository: pckroon/pysmiles

Issue:
Inconsistent writing and reading of mono-atomic smiles for Se and As
If we have a graph featuring a single non-organic atom like Se, this will be outputted by the smiles writer as 'Se'. According to smiles rules, I would have expected '[Se]'. And then, if we again read in the smile 'Se' with the smiles reader, it will fail and output a graph featuring 'S', because it relies on the brackets to recognise non-organic elements.
I don't know if this is an issue with the smiles reader or writer, but they are inconsistent. 

Discussion:

Patch:
diff --git a/pysmiles/smiles_helper.py b/pysmiles/smiles_helper.py
index 86b05e3..0c13c19 100644
--- a/pysmiles/smiles_helper.py
+++ b/pysmiles/smiles_helper.py
@@ -141,8 +141,8 @@ def format_atom(molecule, node_key, default_element='*'):
     if aromatic:
         name = name.lower()
 
-    if (stereo is None and isotope == '' and charge == 0 and default_h and
-            class_ == '' and name.lower() in 'b c n o p s se as *'.split()):
+    if (stereo is None and isotope == '' and charge == 0 and default_h and class_ == '' and
+            (name.lower() in 'b c n o p s *'.split() or name in 'F Cl Br I'.split())):
         return name
 
     if hcount:


Test patch:
diff --git a/tests/test_write_smiles.py b/tests/test_write_smiles.py
index 1b5fa97..d4b2790 100644
--- a/tests/test_write_smiles.py
+++ b/tests/test_write_smiles.py
@@ -130,6 +130,16 @@ from pysmiles.testhelper import assertEqualGraphs, make_mol
          (2, 3, {'order': 1})],
         False
     ),
+    (
+      [(0, {'element': 'Se', 'charge': 0, 'aromatic': False, 'hcount': 0})],
+      [],
+      False
+    ),
+    (
+      [(0, {'element': 'As', 'charge': 0, 'aromatic': False, 'hcount': 0})],
+      [],
+      False
+    ),
 ))
 def test_write_smiles(node_data, edge_data, expl_h):
     mol = make_mol(node_data, edge_data)