is no rule as such. All we can say is that the to-infinitive clause
is used after certain abstract nouns to show what action they relate
to. So we can say:
- She has the ability to achieve good grades at university.
- I had an urge to put salt into his tea when he wasn't
But to-infinitive clauses do not always follow abstract
nouns. If we think of synonyms of ability, such as skill
or aptitude, then the structures which these nouns elicit
are: aptitude for + noun / verb-ing and skill in
verb-ing. Compare the following:
- He shows an aptitude for (working with) figures and
is destined to become an accountant.
- She demonstrated no little skill in bringing the boat
into the harbour in such a rough sea.
It is a matter of learning which prepositional structures are required
after which nouns.