@@ -61,7 +61,8 @@ def pass_cutting_threshold(species):
6161def fails_species_constraints (species ):
6262 """
6363 Pass in either a `Species` or `Molecule` object and checks whether it passes
64- the speciesConstraints set by the user. If not, returns `True` for failing speciesConstraints.
64+ the speciesConstraints set by the user. If the species fails constraints, returns
65+ a string `reason` describing which constraint failed. If all constraints pass, returns `False`.
6566 """
6667
6768 from rmgpy .rmg .input import get_input
@@ -86,57 +87,58 @@ def fails_species_constraints(species):
8687 max_carbon_atoms = species_constraints .get ('maximumCarbonAtoms' , - 1 )
8788 if max_carbon_atoms != - 1 :
8889 if struct .get_num_atoms ('C' ) > max_carbon_atoms :
89- return True
90+ return f"Exceeded maximumCarbonAtoms: { struct . get_num_atoms ( 'C' ) } > { max_carbon_atoms } "
9091
9192 max_oxygen_atoms = species_constraints .get ('maximumOxygenAtoms' , - 1 )
9293 if max_oxygen_atoms != - 1 :
9394 if struct .get_num_atoms ('O' ) > max_oxygen_atoms :
94- return True
95+ return f"Exceeded maximumOxygenAtoms: { struct . get_num_atoms ( 'O' ) } > { max_oxygen_atoms } "
9596
9697 max_nitrogen_atoms = species_constraints .get ('maximumNitrogenAtoms' , - 1 )
9798 if max_nitrogen_atoms != - 1 :
9899 if struct .get_num_atoms ('N' ) > max_nitrogen_atoms :
99- return True
100+ return f"Exceeded maximumNitrogenAtoms: { struct . get_num_atoms ( 'N' ) } > { max_nitrogen_atoms } "
100101
101102 max_silicon_atoms = species_constraints .get ('maximumSiliconAtoms' , - 1 )
102103 if max_silicon_atoms != - 1 :
103104 if struct .get_num_atoms ('Si' ) > max_silicon_atoms :
104- return True
105+ return f"Exceeded maximumSiliconAtoms: { struct . get_num_atoms ( 'Si' ) } > { max_silicon_atoms } "
105106
106107 max_sulfur_atoms = species_constraints .get ('maximumSulfurAtoms' , - 1 )
107108 if max_sulfur_atoms != - 1 :
108109 if struct .get_num_atoms ('S' ) > max_sulfur_atoms :
109- return True
110+ return f"Exceeded maximumSulfurAtoms: { struct . get_num_atoms ( 'S' ) } > { max_sulfur_atoms } "
110111
111112 max_heavy_atoms = species_constraints .get ('maximumHeavyAtoms' , - 1 )
112113 if max_heavy_atoms != - 1 :
113- if struct .get_num_atoms () - struct .get_num_atoms ('H' ) > max_heavy_atoms :
114- return True
114+ heavy_atoms = struct .get_num_atoms () - struct .get_num_atoms ('H' )
115+ if heavy_atoms > max_heavy_atoms :
116+ return f"Exceeded maximumHeavyAtoms: { heavy_atoms } > { max_heavy_atoms } "
115117
116118 max_surface_sites = species_constraints .get ('maximumSurfaceSites' , - 1 )
117119 if max_surface_sites != - 1 :
118120 if struct .get_num_atoms ('X' ) > max_surface_sites :
119- return True
121+ return f"Exceeded maximumSurfaceSites: { struct . get_num_atoms ( 'X' ) } > { max_surface_sites } "
120122
121123 max_surface_bond_order = species_constraints .get ('maximumSurfaceBondOrder' , - 1 )
122124 if max_surface_bond_order != - 1 :
123125 for site in struct .get_surface_sites ():
124126 if site .get_total_bond_order () > max_surface_bond_order :
125- return True
127+ return f"Exceeded maximumSurfaceBondOrder at site: { site . get_total_bond_order () } > { max_surface_bond_order } "
126128
127129 max_radicals = species_constraints .get ('maximumRadicalElectrons' , - 1 )
128130 if max_radicals != - 1 :
129131 if struct .get_radical_count () > max_radicals :
130- return True
132+ return f"Exceeded maximumRadicalElectrons: { struct . get_radical_count () } > { max_radicals } "
131133
132134 max_carbenes = species_constraints .get ('maximumSingletCarbenes' , 1 )
133- if max_radicals != - 1 :
135+ if max_carbenes != - 1 :
134136 if struct .get_singlet_carbene_count () > max_carbenes :
135- return True
137+ return f"Exceeded maximumSingletCarbenes: { struct . get_singlet_carbene_count () } > { max_carbenes } "
136138
137139 max_carbene_radicals = species_constraints .get ('maximumCarbeneRadicals' , 0 )
138140 if max_carbene_radicals != - 1 :
139141 if struct .get_singlet_carbene_count () > 0 and struct .get_radical_count () > max_carbene_radicals :
140- return True
142+ return f"Exceeded maximumCarbeneRadicals: { struct . get_radical_count () } > { max_carbene_radicals } "
141143
142144 return False
0 commit comments