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