Skip to content

Commit 5050436

Browse files
committed
Updated molecule
1 parent d9c0048 commit 5050436

20 files changed

Lines changed: 2269 additions & 1986 deletions

molecule/molecule/adjlist.py

Lines changed: 5 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def saturate(atoms):
5858
"""
5959
new_atoms = []
6060
for atom in atoms:
61-
if not isinstance(atom, Atom): continue
61+
if isinstance(atom, CuttingLabel):
62+
continue
6263
try:
6364
max_number_of_valence_electrons = PeriodicSystem.valence_electrons[atom.symbol]
6465
except KeyError:
@@ -91,7 +92,7 @@ def check_partial_charge(atom):
9192
the theoretical one:
9293
9394
"""
94-
if atom.symbol in ['X','Li']:
95+
if atom.symbol in {'X','L','R','e','H+','Li'}:
9596
return # because we can't check it.
9697

9798
valence = PeriodicSystem.valence_electrons[atom.symbol]
@@ -889,12 +890,11 @@ def to_adjacency_list(atoms, multiplicity, metal='', facet='', label=None, group
889890
Convert a chemical graph defined by a list of `atoms` into a string
890891
adjacency list.
891892
"""
893+
if old_style:
894+
warnings.warn("Support for writing old style adjacency lists has been removed in RMG-Py v3.", RuntimeWarning)
892895
if not atoms:
893896
return ''
894897

895-
if old_style:
896-
return to_old_adjacency_list(atoms, multiplicity, label, group, remove_h)
897-
898898
adjlist = ''
899899

900900
# Don't remove hydrogen atoms if the molecule consists only of hydrogen atoms
@@ -1139,101 +1139,3 @@ def get_old_electron_state(atom):
11391139
else:
11401140
raise InvalidAdjacencyListError("Cannot find electron state of atom {0}".format(atom))
11411141
return electron_state
1142-
1143-
1144-
def to_old_adjacency_list(atoms, multiplicity=None, label=None, group=False, remove_h=False):
1145-
"""
1146-
Convert a chemical graph defined by a list of `atoms` into a string old-style
1147-
adjacency list that can be used in RMG-Java. Currently not working for groups.
1148-
"""
1149-
warnings.warn("The old adjacency lists are no longer supported and may be"
1150-
" removed in version 2.3.", DeprecationWarning)
1151-
adjlist = ''
1152-
1153-
if group:
1154-
raise InvalidAdjacencyListError("Not yet implemented.")
1155-
# Filter out all non-valid atoms
1156-
if not group:
1157-
for atom in atoms:
1158-
if atom.element.symbol in ['He', 'Ne', 'Ar', 'N']:
1159-
raise InvalidAdjacencyListError("Old-style adjacency list does not accept He, Ne, Ar, N elements.")
1160-
1161-
# Don't remove hydrogen atoms if the molecule consists only of hydrogen atoms
1162-
try:
1163-
if remove_h and all([atom.element.symbol == 'H' for atom in atoms]):
1164-
remove_h = False
1165-
except AttributeError:
1166-
pass
1167-
1168-
if label:
1169-
adjlist += label + '\n'
1170-
1171-
# Determine the numbers to use for each atom
1172-
atom_numbers = {}
1173-
index = 0
1174-
for atom in atoms:
1175-
if remove_h and atom.element.symbol == 'H' and atom.label == '': continue
1176-
atom_numbers[atom] = '{0:d}'.format(index + 1)
1177-
index += 1
1178-
1179-
atom_labels = dict([(atom, '{0}'.format(atom.label)) for atom in atom_numbers])
1180-
1181-
atom_types = {}
1182-
atom_electron_states = {}
1183-
if group:
1184-
raise InvalidAdjacencyListError("Not yet implemented.")
1185-
else:
1186-
for atom in atom_numbers:
1187-
# Atom type
1188-
atom_types[atom] = '{0}'.format(atom.element.symbol)
1189-
# Electron state(s)
1190-
atom_electron_states[atom] = '{0}'.format(get_old_electron_state(atom))
1191-
1192-
# Determine field widths
1193-
atom_number_width = max([len(s) for s in atom_numbers.values()]) + 1
1194-
atom_label_width = max([len(s) for s in atom_labels.values()])
1195-
if atom_label_width > 0:
1196-
atom_label_width += 1
1197-
atom_type_width = max([len(s) for s in atom_types.values()]) + 1
1198-
atom_electron_state_width = max([len(s) for s in atom_electron_states.values()])
1199-
1200-
# Assemble the adjacency list
1201-
for atom in atoms:
1202-
if atom not in atom_numbers:
1203-
continue
1204-
1205-
# Atom number
1206-
adjlist += '{0:<{1:d}}'.format(atom_numbers[atom], atom_number_width)
1207-
# Atom label
1208-
adjlist += '{0:<{1:d}}'.format(atom_labels[atom], atom_label_width)
1209-
# Atom type(s)
1210-
adjlist += '{0:<{1:d}}'.format(atom_types[atom], atom_type_width)
1211-
# Electron state(s)
1212-
adjlist += '{0:<{1:d}}'.format(atom_electron_states[atom], atom_electron_state_width)
1213-
1214-
# Bonds list
1215-
atoms2 = list(atom.bonds.keys())
1216-
# sort them the same way as the atoms
1217-
atoms2.sort(key=atoms.index)
1218-
1219-
for atom2 in atoms2:
1220-
if atom2 not in atom_numbers:
1221-
continue
1222-
1223-
bond = atom.bonds[atom2]
1224-
adjlist += ' {{{0},'.format(atom_numbers[atom2])
1225-
1226-
# Bond type(s)
1227-
if group:
1228-
if len(bond.order) == 1:
1229-
adjlist += bond.get_order_str()[0]
1230-
else:
1231-
adjlist += '{{{0}}}'.format(','.join(bond.get_order_str()))
1232-
else:
1233-
adjlist += bond.get_order_str()
1234-
adjlist += '}'
1235-
1236-
# Each atom begins on a new line
1237-
adjlist += '\n'
1238-
1239-
return adjlist

molecule/molecule/atomtype.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ cdef class AtomType:
3939
cdef public list decrement_radical
4040
cdef public list increment_lone_pair
4141
cdef public list decrement_lone_pair
42+
cdef public list increment_charge
43+
cdef public list decrement_charge
4244

4345
cdef public list single
4446
cdef public list all_double

0 commit comments

Comments
 (0)