Catalysis of the reaction: N(2)-formyl-N(1)-(5-phospho-D-ribosyl)glycinamide + L-glutamine + ATP + H(2)O = 2-(formamido)-N(1)-(5-phospho-D-ribosyl)acetamidine + L-glutamate + ADP + 2 H(+) + phosphate.